AHGTH: The Unhandled Exception Handler

I originally wasn’t going to write this post as I thought it was too trivial but Max Cantor talked me into it so here it is.

One of the unfortunate things about GHC is that if an exception occurs on a non-main thread it is silently swallowed by the runtime. The behavior on most runtimes such as the JVM and CLR is that an exception on any thread that is not in a catch block will take down the process. Fortunately GHC provides a hook for providing a global handler for receiving these exceptions. In GHC.Conc.Sync down at the bottom with no docs you will see setUncaughtExceptionHandler. This allows us to pass a handler that GHC will route any exceptions that we don’t catch to. Code sample below.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>