正在处理的异常为什么下面的代码仍然抛出,即使它正在被onFailure处办理斯卡拉未来投掷即使它是失败的的onComplete
val f: Future[Int] = Future {
Thread.sleep(10)
1/0
1
}
f.onComplete {
case Success(value) => println(value)
case Failure(ex)=> println(ex)
}
Await.result(f, Duration.Inf) // throws an Arithmetic exception
使用'recover'。 'onComplete'只是作为执行结果执行的exta回调。 – Rumoku