top | item 5053852

(no title)

arturaz | 13 years ago

How about onFailure?

discuss

order

noelwelsh|13 years ago

Let me expand: there is nothing in the type system that will make you handle exceptions in Futures, in the way that Option or Either make you handle the failure case. It is easy for a Future to fail and you to never see a stack trace. E.g. this will silently fail:

  Future { 1 / 0 }
An alternative is to encode the possibility of failure in the type system by using Future[Validation[E,A]] (replace Validation with Try or Either as the whim takes you). Then the type system will remind you to handle the failure case. See my link above for more (scroll down a bit to see the section on error handling).

mmaltiar|13 years ago

I focussed on a example with a happy flow. In Akka Futures you can handle only error conditions of the following type.

for example we have future onSuccess future onFailure

or we have onComplete, future onComplete { case Success(result) ⇒ doSomethingOnSuccess(result) case Failure(failure) ⇒ doSomethingOnFailure(failure) }

else you can follow what is mentioned by noelwalsh