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

后端 未结 6 1124
我在风中等你
我在风中等你 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:54

    Or use Future.liftTryTry, turns it from Future[Object] to Future[Try[Object]], and you can match on the Try[Object] and check for an exception case Throw(e) and log / exit gracefully

提交回复
热议问题