haskell - 捕获 `error` 引发的错误?

标签 haskell exception-handling either

有一些 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/

相关文章:

haskell - 使用 ErrorT 累积错误

postgresql - Yesod persistent-postgresql rawSql 查询与列列表通配符产生语法错误

ruby-on-rails - rake 任务中的 Rails 异常通知程序

c# - CodedUI 测试 - 为整个测试集启动一次浏览器

exception - 何时对域类中的异常使用断言

java - 在rest api中返回Either (Vavr)

haskell - Haskell 中的纯错误处理,带有 : how to fold with error possibility?

haskell - 是否可以使用 haskell-gi 比较两个 gobject 并找出它们是否相同?

haskell - 如何让 Haskell 的 TChan 像 Erlang 的消息队列一样延迟消息?

haskell - 当你依赖一个 cabal 包时,它似乎会在所有 cabal 节中引入依赖关系