> Hi all. I am porting to Haskell a small zlib-based library for .zip files (I > have not seen any released package for it, although it should very useful). The > matters come when I try to address exceptional conditions: all the library > functions return a integer code with OK/SOMEERROR meaning. The most natural way > to carry the exceptional situations should be raise IO exceptions,
Sometimes you can just encode your exceptional values in some type. It tends to be more declarative than throwing/catching exceptions: data Result = Ok Int | ThisError | ThatError String | SomeError Int ... And you library functions can be: fun :: Foo -> Bar -> IO Result drop the IO type if you don't need it. > 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. I think that very modern versions of Hugs support some of this extension too. Cheers, Bernie. _______________________________________________ Haskell-Cafe mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/haskell-cafe
