Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception handling with Akka actors

Does the exception generated by a function within the child actor have to be caught and thrown by the child actor explicitly or will the supervisor strategy directives(escalate) take care of percolating the generated exception to the supervisor actor behind the scenes?

My supervisor strategy:

  override val supervisorStrategy =
OneForOneStrategy(maxNrOfRetries = 5, withinTimeRange = 5 minute) {
  case _: ArithmeticException      ⇒ Resume
  case _: NullPointerException     ⇒ Restart
  case _: IllegalArgumentException ⇒ Stop
  case _: IOException              ⇒ Stop
  case _: Exception                ⇒ Restart
}   

And some of the operations within the child actor could possibly throw an IOException. Should I put a try catch block in the child actor to catch it and then throw it so that the supervisor can catch it? Or will akka take care of it behind the scenes?


1 Answers

In case you have nothing to lose, let it crash. It should be the default behaviour. But unfortunately sometimes you need to allocate resources or you need to information about what happened when things went wrong.

Personally I usually catch all the exceptions I would like to inform about what is going on when I am creating endpoints or web applications.

like image 156
Carlos Vilchez Avatar answered Dec 08 '25 00:12

Carlos Vilchez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!