[Haskell-cafe] Printing of asynchronous exceptions to stderr

Mitar mmitar at gmail.com
Wed Nov 10 12:52:44 EST 2010


On Wed, Nov 10, 2010 at 4:16 PM, Simon Marlow <marlowsd at gmail.com> wrote:
> The right way to fix it is like this:

Optimist. ;-)

>  let run = unblock doSomething `catches` [
>                Handler (\(_ :: MyTerminateException) -> return ()),
>                Handler (\(e :: SomeException) -> putStrLn $ "Exception: " ++
> show e)
>              ] `finally` (putMVar terminated ())
>  nid <- block $ forkIO run

In 6.12.3 this does not work (it does not change anything, I hope I
tested it correctly) because finally is defined as:

a `finally` sequel =
  block (do
    r <- unblock a `onException` sequel
    _ <- sequel
    return r

You see that unblock there? So it still unblocks so that second
exception is delivered immediately after catches handles the first

But I agree that your explanation for what is happening is the correct
one. Better than my "hanging threads at the end". And with my throwIO
approach I just override MyTerminateException with ThreadKilled.


More information about the Haskell-Cafe mailing list