使用 scala.util.control.Exception
有没有人有使用 scala.util.control.Exception
版本 2.12.0 (版本 2.8.0), ?我正在努力从类型中找出答案。
Does anybody have good examples of using scala.util.control.Exception
version 2.12.0 (version 2.8.0), ? I am struggling to figure it out from the types.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确实 - 我也觉得这很令人困惑!这是一个问题,我有一些可能是可解析日期的属性:
将其切换为函数形式:
在上面的代码中,将
捕捉(t)任一expr
将导致Either[ T, E]
其中T
是 throwable 的类型,E
是表达式的类型。然后可以通过折叠将其转换为特定值。或者另一个版本:
这可能更清楚一些 - 以下是等效的:
Indeed - I also find it pretty confusing! Here's a problem where I have some property which may be a parseable date:
Switching this to a functional form:
In the above code, turns
catching(t) either expr
will result in anEither[T, E]
whereT
is the throwable's type andE
is the expression's type. This can then be converted to a specific value via afold
.Or another version again:
This is perhaps a little clearer - the following are equivalent:
以下是一些示例:
compiler/scala/tools/nsc/interpreter/InteractiveReader.scalacompiler
/scala/tools/nsc/Interpreter.scalacompiler
/scala/tools/nsc/io/Process.scalalibrary
/scala/xml/include/ sax/Main.scala
Here are some examples:
compiler/scala/tools/nsc/interpreter/InteractiveReader.scala
compiler/scala/tools/nsc/Interpreter.scala
compiler/scala/tools/nsc/io/Process.scala
library/scala/xml/include/sax/Main.scala