简体   繁体   English

Haskell惰性异常 - 区分多个异常?

[英]Haskell lazy exceptions — distinguishing between multiple exceptions?

The Haskell "zlib" library wraps the C library and lazily decompresses. Haskell“zlib”库包装C库并且懒惰地解压缩。 The "decompress" function in this library can throw exceptions only catchable in the IO monad. 此库中的“解压缩”功能可以抛出只能在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. 我需要聪明地恢复。

The way the code looks you can't do any better than match the string. 代码看起来的方式不能比匹配字符串做得更好。 You need to change something, maybe use foldDecopressionStream yourself? 你需要改变一些东西,也许你自己使用foldDecopressionStream?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM