3

I'm new to the actor model and I wonder how runtime errors should be handled.

Suppose actor catches exception, what should it do then?

I definitely want the sender to be notified of any errors, so, at least sender could log the errors.

Should all the response messages contain status field or should there exist XXXErrorMessage class for every response message in my application?

What are best practices for error handling in actor model?

lambdas
  • 3,990
  • 2
  • 29
  • 54
  • 1
    Send back a None, or even better [Left](http://stackoverflow.com/questions/1193333/using-either-to-process-failures-in-scala-code). Alternatively, you may just [let it fail](http://akka.io/docs/akka/1.1.1/scala/fault-tolerance.html) – om-nom-nom Sep 11 '12 at 12:12
  • om-nom-nom: Good point, just bump up akka version to 2.x: http://doc.akka.io/docs/akka/2.0.3/scala/fault-tolerance.html – ron Sep 11 '12 at 15:03
  • I would also recommend this read about supervision hierarchy: http://doc.akka.io/docs/akka/2.0.3/general/supervision.html – ron Sep 11 '12 at 15:06

1 Answers1

2

You should google "erlang supervisor design", since the Actor model was mostly paved in erlang. Then you can apply the described knowledge with Akka actors (which is becoming standard actor lib in Scala 2.10). Also read the above commented akka docs on supervision and fault tolerance.

Alternatively, you might choose not to use Actors, but Futures instead, which are easier to compose. Then you will have Future[Either[E, A]] types, which you can treat as a combined EitherT[Future, E, A] monad type using scalaz + akkaz and use it in for comprehensions for example.

I would go with Actors if I expect a lot of failure, need to restart and retry things, having to encapsulate mutable state, etc. If you don't need these, you may fall back to Futures and have a better sleep.

ron
  • 9,262
  • 4
  • 40
  • 73