[Haskell-cafe] Printing of asynchronous exceptions to stderr
mmitar at gmail.com
Wed Nov 10 04:50:07 EST 2010
On Wed, Nov 10, 2010 at 8:54 AM, Bas van Dijk <v.dijk.bas at gmail.com> wrote:
> A ThreadKilled exception is not printed to stderr because it's not
> really an error and should not be reported as such.
So, how to make custom exceptions which are "not really an error"?
> What do you mean by "hanging there". Are they blocked on an MVar?
I have something like this:
terminated <- newEmptyMVar
forkIO $ doSomething `catches` [
Handler (\(_ :: MyTerminateException) -> return
()), -- we just terminate, that is the idea at least
Handler (...) -- handle other exceptions
] `finally` (putMVar terminated ())
The problem is, that if I send multiple MyTerminateException
exceptions to the thread one of them is printed (or maybe even more, I
do not know, because I have many threads). My explanation is that
after the first one is handled and MVar is written, thread stays
"active", just no computation is evaluating. Because of that another
exception can be thrown at the thread. And then it is not handled
anymore and so the library prints the exception and exits the thread.
If I change things into:
`finally` (putMVar dissolved () >> throwIO ThreadKilled)
it works as expected.
> That shouldn't be necessary. If the cleanup action is the last action
> of the thread then the thread will terminate when it has performed the
It does not seem so.
> It would help if you could show us your code (or parts of it).
I hope the code above should satisfy. If not I will make some real example.
More information about the Glasgow-haskell-users