[MLton-user] Stack Traces
Matthew Fluet
fluet at tti-c.org
Fri Mar 23 08:08:36 PST 2007
Yes, MLton.CallStack is the way to access the current call stack. You
could define something like:
fun noisyRaise exn =
let
val cs = MLton.CallStack.current ()
val () = print (concat ["raising ",
exnName exn,
" with stack:\n"])
val () = List.app (fn s => (print s; print "\n"))
(MLton.CallStack.toStrings cs)
in
raise exn
end
You will need to compile your program with "-profile call" to instruct
the compiler to save the call stack information; without this, the above
program will have an empty list of strings.
Of course, as Vesa mentioned, if the exception being raised is an
uncaught exception, then compiling with "-const 'Exn.keepHistory true'"
will have the top-level exception handler print out the call stack from
the point of the raise. But, if you have an intervening handle, then
you'll want noisyRaise (or use MLton.Exn.history at the point of the
handle).
Vesa Karvonen wrote:
> Looking at the MLton structure, there seems to be CallStack
> substructure (not documented in the wiki) that might do what
> you want (I've never used it, I just print out the stack trace
> using MLton.Exn.history in an exception handler). See here:
> http://mlton.org/cgi-bin/viewsvn.cgi/mlton/trunk/basis-library/mlton/mlton.sig?view=auto
>
> http://mlton.org/cgi-bin/viewsvn.cgi/mlton/trunk/basis-library/mlton/call-stack.sig?view=auto
>
>
> -Vesa Karvonen
>
> On 3/23/07, Neal Glew <neal at glew.name> wrote:
>> I'm about to throw an exception and I want to print out a stack trace
>> (ie, list of all frames on the call stack and which function and line
>> number they are in). What is the best way to do this in MLton?
>>
>> Neal
>
> _______________________________________________
> MLton-user mailing list
> MLton-user at mlton.org
> http://mlton.org/mailman/listinfo/mlton-user
>
>
>
More information about the MLton-user
mailing list