有一些 stdlib 函数会在无效输入时引发错误。例如:
Prelude> read "1o2" :: Int
*** Exception: Prelude.read: no parse
我想包装它以返回
Either e a
反而。我怎样才能做到这一点?
最佳答案
There is no spoon.你没有从我这里听到。
但是,对于这个特定示例,您应该使用 reads
反而。
关于haskell - 捕获 `error` 引发的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10926855/