Reputation: 1071
Why does this print "Success" instead of "Failure"? How to catch Future.failed?
object HelloScala extends App{
val f = future
f.map { result => println("Success")
}.recover { case e =>
println(e.getMessage)
}
def future = Future {
Future.failed(new Throwable("Failure"))
}
Thread.sleep(10000)
}
Upvotes: 0
Views: 176
Reputation: 51271
Look at the type of f
.
val f: Future[Future[_]] = future
The inner Future
fails but the outer Future
completes with Success
.
Upvotes: 2