PROPOSAL: Add displayException to Exception typeclass

Simon Hengel sol at typeful.net
Tue Nov 11 02:38:45 UTC 2014


> > 2.  Add a function that can be invoked to change the default handler.
> 
> like
> 
> http://hackage.haskell.org/package/base-4.7.0.1/docs/GHC-Conc-Sync.html#v:setUncaughtExceptionHandler

I think getting the exception handler right is non-trivial, e.g.

 - stdout has to be flushed, ignoring any exceptions while doing so
 - output has to go to stderr, not stdout
 - program has to terminate with the correct exit code (at least if it's
   the main thread)
 - I would also assume that ExitCode exceptions need special handling,
   even though I don't see any code for that in the default handler [1],
   so maybe this is already taken care of before the handler is invoked

So I think it makes sense to provide a primitive along the lines of

    useDisplayExceptionHandler :: IO ()

which does "the right thing" (I'm not very opinionated about the name).

One more thing I noticed is that the exception handler set with
setUncaughtExceptionHandler is used for both the main thread and other
threads.  I'm undecided whether this would be desirable or not for
useDisplayExceptionHandler.  Thoughts?

Cheers,
Simon

[1] http://hackage.haskell.org/package/base-4.7.0.1/docs/src/GHC-Conc-Sync.html#uncaughtExceptionHandler


More information about the Libraries mailing list