How is ExitCode handled?

Tom Ellis tom-lists-haskell-cafe-2023 at jaguarpaw.co.uk
Mon Oct 21 11:02:18 UTC 2024


On Sun, Oct 20, 2024 at 01:24:34PM +0100, Tom Ellis wrote:
> On Sun, Oct 20, 2024 at 01:06:01PM +0100, Tom Ellis wrote:
> > From my experiements with a small program (below) I conclude that the
> > default handler is installed on every thread, and real_handler is
> > installed *on the main thread only* *below* the default handler, so
> > that if an `ExitCode` exception is thrown the default handler never
> > gets a chance to see it.
> 
> Oh, I see that the uncaught exception handler is called in
> `reportError`, itself used by `real_handler`, thence `child_handler`,
> and `forkIO`.
> 
>     https://hackage.haskell.org/package/ghc-internal-9.1001.0/docs/src//GHC.Internal.Conc.Sync.html#reportError
> 
> It's also used by the `real_handler` in TopHandler.hs, and thence
> `topHandler` and `runIO`.
> 
>     https://hackage.haskell.org/package/ghc-internal-9.1001.0/docs/src/GHC.Internal.TopHandler.html
> 
> So the uncaught exception handler is not really "installed", it's just
> used by the handlers installed by `forkIO` and `runMainIO` (the latter
> wraps main, as per the documentation).
> 
> So I think I probably understand what's going on now.

I wrote a short article on my findings:

    https://h2.jaguarpaw.co.uk/posts/exitfailure-doesnt-exit/

Tom


More information about the ghc-devs mailing list