How do I get hold of exceptions thrown in a Scala Future?

后端 未结 6 1131
我在风中等你
我在风中等你 2020-12-06 10:30

I\'ve been working up my answer to Is there a standard Scala function for running a block with a timeout?, and have run into a problem if an exception is thrown in a Future.

6条回答
  •  醉酒成梦
    2020-12-06 10:41

    scala.concurrent.ops.future includes exception handling.

    So, instead of importing scala.actors.Futures.future, import scala.concurrent.ops.future instead.

    That simple change in which import is there will cause the caller's call to .get to rethrow the exception. It works great!

提交回复
热议问题