def testThrowException(number: Int): Future[Int] = {
if (number == 0) {
throw new Exception("number is 0")
else {
Future{1}
}
Run Code Online (Sandbox Code Playgroud)
对于上述函数,如果我用 testThrowException(0) 调用它,我可以看到控制台中打印的异常错误消息,但如果我执行类似的操作
def testThrowException(number: Int): Future[Int] = {
anotherFuture.map {
if (number == 0) {
throw new Exception("number is 0")
} else {
1
}
}
Run Code Online (Sandbox Code Playgroud)
我看不到控制台中打印的异常,但是如果我执行 testThrowException.onFailure,我可以看到失败消息,我在这里做错了什么吗?为什么不打印出异常