[Haskell-cafe] Tricky exception handling
Joel Reymont
joelr1 at gmail.com
Mon Dec 12 04:30:27 EST 2005
Folks,
I have a thread that launches socket reader and writer threads. My
intent is to notify the main thread when an exception is caught by
the reader/writer. Is this code proper?
---
withException :: (Event a -> IO ())
-> IO ()
-> IO Bool
withException post action =
handle (\e -> do case e of
AsyncException ThreadKilled -> return ()
_ -> post $ NetworkError e
return False
) $ do { action; return True }
writeLoop :: (Event a -> IO ()) -> Handle -> (SSL, BIO, BIO) -> IO ()
writeLoop post h ssl =
do go <- withException post $
do cmd <- read h ssl
post $! Cmd $! cmd
when go $ writeLoop post h ssl
---
Thanks, Joel
--
http://wagerlabs.com/
More information about the Haskell-Cafe
mailing list