Thanks for the quick reply.

But how do I handle the Exceptions at a common place instead of try-catch 
in each of the actors? (like SQL Exceptions )


On Tuesday, July 1, 2014 6:48:17 PM UTC+5:30, √ wrote:
>
> I'd recommend against using Exceptions for validation. The non-existence 
> of an Employee is a natural thing given an arbitrary id—it is not 
> exceptional.
>
>
> On Tue, Jul 1, 2014 at 3:08 PM, Yadukrishnan K <yada...@gmail.com 
> <javascript:>> wrote:
>
>> So do I have to do it in each of the actors ?
>> Is there any other way to handle it in a central place? For ex: in Spring 
>> MVC, all the exceptions thrown from the controller can be handled using 
>> @ControllerAdvice. Just looking if there is any similar thing.
>>
>> Not just this, I want to handle any SQLExceptions like Constraint 
>> Violation and return a meaningful message to the caller. For that also, I 
>> need to use try-catch in each of the actors and send corresponding message ?
>>
>>
>>
>>
>> On Tuesday, July 1, 2014 6:27:42 PM UTC+5:30, Yadukrishnan K wrote:
>>>
>>> I am a newbie to akka actor system. I am developing an application using 
>>> Java, Spring, Hibernate and Akka. 
>>> I am having problems with exception handling. 
>>>
>>> My scenario is given below :
>>>
>>> REST API --> Spring MVC --> Service Layer (Actor) --> Hibernate 
>>> Repository.
>>> Assume that I am trying to find an employee with id 1. 
>>>
>>> Employee emp = HibernateRepository.findById(Employee.class, id);
>>> sender().tell(emp, self());
>>>
>>> If the employee with id=1 doesn't exist, the emp object will be NULL and 
>>> sending NULL as message will throw InvalidMessageException. 
>>> Is it possible to handle this exception and throw a custom Exception to 
>>> the caller, say NoEntityFoundException? This help me to check if the result 
>>> I obtained is of Employee or CustomException. Currently, I am getting 
>>> Future timeout only. 
>>>
>>> I have a BaseActor which extends akka.actor.AbstractActor. I also have 
>>> another class, BaseModuleActor which extends BaseActor, as shown below.
>>>
>>> public class BaseModuleActor extends BaseActor {
>>>
>>>     public  <T> ActorRef getActorRef(ActorSystem system,Class<T> clazz){
>>>         return system.actorOf(
>>>                 SpringExtension.SpringExtProvider.get(system).
>>> props(clazz));
>>>     }
>>> }
>>>
>>> All my actors are extending this actor, where I am doing like below
>>>
>>> @Override
>>>     public PartialFunction<Object, BoxedUnit> receive(){
>>>       return ReceiveBuilder
>>>               .match(Long.class, id-> getEmployeeById(id))
>>>               .build()
>>>               .orElse(matchAny());
>>>     }
>>> private void getEmployeeById(Long id){
>>>        Employee emp = HibernateRepository.findById(Employee.class, id);
>>>        sender().tell(emp, self());
>>>     }
>>>
>>>
>>> But I am now stuck with handling the exceptions at a common place using 
>>> the supervisor strategy. 
>>> How can I catch the InvalidMessageException and resends some meaningful 
>>> message to the caller. Is it possible? 
>>>
>>>
>>> Regards,
>>> Yadu
>>>
>>  -- 
>> >>>>>>>>>> Read the docs: http://akka.io/docs/
>> >>>>>>>>>> Check the FAQ: 
>> http://doc.akka.io/docs/akka/current/additional/faq.html
>> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Akka User List" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to akka-user+...@googlegroups.com <javascript:>.
>> To post to this group, send email to akka...@googlegroups.com 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/akka-user.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Cheers,
> √
>  

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to