functor ExnHandler(structure T: TOKENIZER; structure P: PPC): EXN_HANDLER = struct val eprintf = fn z => printf `"error: " z fun otherExn e = let val hist = MLton.Exn.history e in eprintf `"exception " `(exnMessage e) `" was raised\n"; if hist = [] then printf `"No stack trace is avaliable\n" `"Recompile with -const \"Exn.keepHistory true\"\n" % else List.app (fn x => printf `"\t" `x `"\n" %) hist end fun ioExn (IO.Io { name, function = _, cause }) = let val reason = case cause of OS.SysErr (str, _) => str | _ => exnMessage cause in eprintf `name `": " `reason `"\n" % end | ioExn _ = die 126 `"ioExn: unreachable\n" % fun handler e = ( printf `"\n"; case e of T.FsmTableIsTooSmall => eprintf `"fsm table is too small. Increate 'maxState' value\n" % | IO.Io _ => ioExn e | T.TkErrorAug (pos, msg) => eprintf T.S.Ppos pos `": " `msg `"\n" % | P.TkError v => P.tkErrorPrint v | P.TkClassError v => P.tkClassErrorPrint v | _ => otherExn e; exit 1 ) handle _ => sysExit 127 end