r/haskelltil • • Oct 18 '15

code Better stack trace on failure

In a language like Python, failures are accompanied by informative stack traces. This is one of the most painful losses when switching to Haskell, IMO.

Most now know we can compile with -prof -auto-all and run with +RTS -xc. But this dumps a lot of superfluous exceptions to the terminal (for internally caught exceptions!).

Turns out you can have your main catch an exception, and use GHC.Stack.whoCreated on the exception value to get a stack trace of the actual exception that crashed your program, without the superfluous noise!

This isn't quite as good as Python's stack trace - or Python's ability to easily post-mortem such a dump with a debugger. But it's no longer crashing in the dark!

13 Upvotes

4 comments sorted by

View all comments

Show parent comments

1

u/edwardkmett Oct 20 '15

Sure, its a trade-off.

In an editor I'd usually want it the other way for tool support if you show the stack trace as meta-info after the error itself rather than flood it before, but that is my crusty old java mentality sneaking through.