Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 470
romul Avatar asked Nov 06 '22 00:11

romul


1 Answers

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

like image 65
augustss Avatar answered Nov 09 '22 08:11

augustss