There is flexible exception handling in Haskell?
droundy at abridgegame.org
Tue Nov 18 06:31:29 EST 2003
On Tue, Nov 18, 2003 at 12:40:45PM +1100, Bernard James POPE wrote:
> > but here comes the problem: how can I define new Exception codes,
> > instead of raising userError all the time? I think it makes sense for a
> > library to raise specialized exceptions, instead of userErrors. There
> > is such a mechanism? Can someone help?
> If the encoding doesn't somehow suit your needs then you could try GHC's
> exception extensions, which provide a much richer exception facility than
> plain Haskell 98
> Have a look at the module Control.Exception in the user docs.
You could also check out System.IO.Error, which allows you to define (and
of course, raise) IOErrors, which is probably closer to what you want (see
mkIOError). If you use System.Exception to define errors of type
Exception, then you'll need to use System.Exception.catch to catch them.
If you define errors of type ioError, then the prelude catch will catch
them, which is more likely what you want.
More information about the Haskell-Cafe