[Haskell] Better Exception Handling

Scott Turner p.turner at computer.org
Wed Nov 24 18:29:14 EST 2004

John Goerzen wrote:
> I note, though, that "making an Either into a Monad" doesn't do
> anything to deal with asynchronous exceptions.
[ snip]
> I was referring to exceptions generated by things such as signals,
> interrupts, certain network errors, stack problems, etc.

How would you like asynchronous exceptions to fit in?  Your original request 
mentioned that it was annoying to have to use the IO monad for all 
exceptions, particularly when the exceptions occur in deterministic code.  
But the IO monad is plainly appropriate for asynchronous exceptions.

If what you need is to catch asynchronous exceptions as soon as possible and 
propogate them as Either-based exceptions, then my sample code can be readily 
extended in that way.  For example, you could catch a network error and 
propogate it with a message saying that the error occurred during an FTP 
write operation. This is possible because the monad that's used for the FTP 
module combines Either with IO.

More information about the Haskell mailing list