[MLton] MLton bug: unhandled exception in Basis Library.

Matthew Fluet fluet at tti-c.org
Tue Dec 16 08:37:38 PST 2008

On Mon, 15 Dec 2008, Nicolas Bertolotti wrote:
> Not really what I am looking for... (I already know how to use the exception history)
> The problem here is that the exception occurs at program startup during the initialisation of the basis library.
> At this stage, there is no real way to catch the exception and print the history.

The "fancy" top-level exception handler, that prints the history, is 
implemented in
and "installed" by 'Primitive.TopLevel.setHandler' in

An unhandled exception that is raised during the evaluation of the Basis 
Library before the installation of the "fancy" top-level exception handler 
is handled by the "emergency" top-level exception handler that is 
"installed" in

If you want the emergency exception handler to print an exception history, 
then you need to move (some portion of) the fancy exception handler 
implementation back to the implementation of the emergency handler.  In 
particular, you need to call 'Primitive.MLton.Exn.setExtendExtra' with a 
non-trivial function that captures the call-stack and you need to walk the 
call-stack, extract the entries, and print them.  It won't be trivial, 
since, at the point of definition of the emergency exception handler, you 
have almost no Basis Library functions available; everything will need to 
be done with very primitive operations.

More information about the MLton mailing list