[Haskell-cafe] Tricky exception handling
joelr1 at gmail.com
Mon Dec 12 11:26:23 EST 2005
I would welcome suggestions for improvements. Please let me know how
my code could be made more efficient and more readable, keeping in
mind what I'm trying to accomplish.
Notice that my logic is different from the one that you are proposing.
What I want is to handle exceptions in the forever loop _and_
terminate the forever loop when an exception is posted. The only
reason I have the exception handler is that I want to post a message
when the exception is received, unless it's a KillThread exception.
Unless I'm mistaken, the code above will run forever and will not
exit on exception.
I use the code like this:
tid1 <- forkIO $ writeLoop post h ssl
`finally` finalize sock_lock ssl_lock
but indeed no message will be posted if an exception happens between
the calls to handle and things will just be silently finalized. I'm
not sure how to have it both ways here.
On Dec 12, 2005, at 11:29 AM, Bulat Ziganshin wrote:
> Hello Joel,
> your code is unreadable, inefficent and don't handle async exceptions
> between calls to `handle`. as i already sayed you'd better to use:
> handle (...)
> do cmd <- read h ssl
> post $! Cmd $! cmd
More information about the Haskell-Cafe