You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by "Robert A. Decker" <de...@robdecker.com> on 2013/05/28 14:25:23 UTC

throwing exceptions in services

Hello,

Generally, how do people handle exceptions in your exposed service methods? Do you generally throw your own typed exceptions from the service method and have the calling component handle the exception, even if its in a different bundle? Or do you throw unhandled runtime exceptions from service methods and have the called service method take care of its own errors?

Or a mix of the above? 

Rob

Re: throwing exceptions in services

Posted by Felix Meschberger <fm...@adobe.com>.
Hi David,

Just to be sure: The Activate method is generally not part of the Service (API, interface, contract) but an implementation detail the service consumer must not care about.

But from an implementors POV, you are fully correct: Declarative services call-back methods should not throw exceptions.

Regards
Felix

Am 28.05.2013 um 16:25 schrieb David G.:

> Robert,
> 
> Unhandled exceptions thrown in the Activate method in service will prevent
> the service itself from being registered. The logic in these methods
> probably should be naturally scoped to this effect (if an activate
> exception is thrown then probably the service isnt ready to be used
> anyhow), but its worth noting and you should be mindful as define the
> routines in your activate method.
> 
> 
> On Tue, May 28, 2013 at 8:30 AM, Felix Meschberger <fm...@adobe.com>wrote:
> 
>> Hi
>> 
>> It really depends. I think it is perfectly fine for a service to define
>> exceptions to be thrown in case of error. This may be checked exceptions
>> (in the signature of the method) or unchecked exceptions (just listed in
>> JavaDoc).
>> 
>> It really depends on the use case and requirements of the exposed API. At
>> the end of the day, this is the same as plain Java: Your API and its
>> contract define whether to throw exceptions and what exceptions to throw.
>> Concentrate on the API to define this and don't care about higher level use
>> of your API -- that would be none of the APIs business.
>> 
>> Regards
>> Felix
>> 
>> Am 28.05.2013 um 14:25 schrieb Robert A. Decker:
>> 
>>> Hello,
>>> 
>>> Generally, how do people handle exceptions in your exposed service
>> methods? Do you generally throw your own typed exceptions from the service
>> method and have the calling component handle the exception, even if its in
>> a different bundle? Or do you throw unhandled runtime exceptions from
>> service methods and have the called service method take care of its own
>> errors?
>>> 
>>> Or a mix of the above?
>>> 
>>> Rob
>> 
>> 


Re: throwing exceptions in services

Posted by "David G." <da...@gmail.com>.
Robert,

Unhandled exceptions thrown in the Activate method in service will prevent
the service itself from being registered. The logic in these methods
probably should be naturally scoped to this effect (if an activate
exception is thrown then probably the service isnt ready to be used
anyhow), but its worth noting and you should be mindful as define the
routines in your activate method.


On Tue, May 28, 2013 at 8:30 AM, Felix Meschberger <fm...@adobe.com>wrote:

> Hi
>
> It really depends. I think it is perfectly fine for a service to define
> exceptions to be thrown in case of error. This may be checked exceptions
> (in the signature of the method) or unchecked exceptions (just listed in
> JavaDoc).
>
> It really depends on the use case and requirements of the exposed API. At
> the end of the day, this is the same as plain Java: Your API and its
> contract define whether to throw exceptions and what exceptions to throw.
> Concentrate on the API to define this and don't care about higher level use
> of your API -- that would be none of the APIs business.
>
> Regards
> Felix
>
> Am 28.05.2013 um 14:25 schrieb Robert A. Decker:
>
> > Hello,
> >
> > Generally, how do people handle exceptions in your exposed service
> methods? Do you generally throw your own typed exceptions from the service
> method and have the calling component handle the exception, even if its in
> a different bundle? Or do you throw unhandled runtime exceptions from
> service methods and have the called service method take care of its own
> errors?
> >
> > Or a mix of the above?
> >
> > Rob
>
>

Re: throwing exceptions in services

Posted by Felix Meschberger <fm...@adobe.com>.
Hi

It really depends. I think it is perfectly fine for a service to define exceptions to be thrown in case of error. This may be checked exceptions (in the signature of the method) or unchecked exceptions (just listed in JavaDoc).

It really depends on the use case and requirements of the exposed API. At the end of the day, this is the same as plain Java: Your API and its contract define whether to throw exceptions and what exceptions to throw. Concentrate on the API to define this and don't care about higher level use of your API -- that would be none of the APIs business.

Regards
Felix

Am 28.05.2013 um 14:25 schrieb Robert A. Decker:

> Hello,
> 
> Generally, how do people handle exceptions in your exposed service methods? Do you generally throw your own typed exceptions from the service method and have the calling component handle the exception, even if its in a different bundle? Or do you throw unhandled runtime exceptions from service methods and have the called service method take care of its own errors?
> 
> Or a mix of the above? 
> 
> Rob