romul
romul

Reputation: 51

Haskell lazy exceptions -- distinguishing between multiple exceptions?

The Haskell "zlib" library wraps the C library and lazily decompresses. The "decompress" function in this library can throw exceptions only catchable in the IO monad.

The type is this:

decompress :: ByteString -> ByteString

It uses the following:

  foldDecompressStream L.Chunk L.Empty
    (\_code msg -> error ("Codec.Compression.Zlib: " ++ msg))

Obviously it's possible for a data stream to be corrupted, which will cause an exception to be generated.

If I need to be catching multiple exceptions due to different causes, how can I tell one exception from another, other than by trying to match on the text (which has all sorts of negatives) ? I need to recover intelligently.

Upvotes: 5

Views: 224

Answers (1)

augustss
augustss

Reputation: 23014

The way the code looks you can't do any better than match the string. You need to change something, maybe use foldDecopressionStream yourself?

Upvotes: 2

Related Questions