I'm using Scala's For comprehension to wait until several futures will be executed. But I want also to handle the onFailure
(I want to write error message to log). How I can achieve it?
This is my code:
val f1 = Future {...}
val f2 = Future {...}
for {
res1 <- f1
res2 <- f2
} {
// this means both futures executed successfully
process(res1, res2)
}
If you only want to write an error message to a log file you can just chain your error logging onto the
onFailure
part:This would print out:
As you see the issue with this is that things might happen out of order and the logging might be far away from when the Exception is eventually logged.