lambdas
lambdas

Reputation: 4088

How actor should notify sender of errors?

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?

Upvotes: 3

Views: 354

Answers (1)

ron
ron

Reputation: 9396

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.

Upvotes: 2

Related Questions