【发布时间】:2019-08-15 01:07:07
【问题描述】:
我想使用 catchAll 或 catchSome 处理 ZIO 中的一些异常,如下所示:
object Test extends App {
def run(args: List[String]) =
myApp.fold(_ => 1, _ => 0)
val myApp =
for {
_ <- putStrLn(unsafeRun(toINT("3")).toString)
} yield ()
def toINT(s: String): IO[IOException, Int]= {
IO.succeed(s.toInt).map(v => v).catchAll(er =>IO.fail(er))
}
如果我传递了一个有效的格式号,代码会成功,但如果我传递了无效的格式和想法,它就无法处理异常??
【问题讨论】:
-
为什么
unsafeRun在你的 IO 中间?我想你想要for { i <- toINT("3"); _ <- putStrLn(i.toString)} yield ()
标签: scala error-handling zio