[Haskell-cafe] System.Exit

Tomasz Zielonka tomasz.zielonka at gmail.com
Thu Jul 5 03:58:21 EDT 2007

On Wed, Jul 04, 2007 at 11:16:20PM -0700, Stefan O'Rear wrote:
> The documentation says:
> | Computation exitWith code throws ExitException code. Normally this
> | terminates the program, returning code to the program's caller. Before
> | the program terminates, any open or semi-closed handles are first
> | closed.                                                                                                                                                                                                          
> | 
> | As an ExitException is not an IOError, exitWith bypasses the error
> | handling in the IO monad and cannot be intercepted by catch from the
> | Prelude. However it is an Exception, and can be caught using the
> | functions of Control.Exception. This means that cleanup computations
> | added with bracket (from Control.Exception) are also executed properly
> | on exitWith.
> Probably some part of your code is catching all exceptions, printing
> them, and then ignoring them; thus negating the exit request.

I think the problem here is that uncaught exception are not propagated from
child threads to the main thread (I'm not claiming that they should be)
and ExitException only ends the program when caught in the main thread,
as it seems. Try this:

    import Control.Concurrent
    import System.Exit

    main = do
        forkIO $ exitWith ExitSuccess
        threadDelay 10000000

Best regards

More information about the Haskell-Cafe mailing list