[webbeans-dev] IllegalArgumentException (Was: Re: Updated EJB SPI)

Carlo de Wolf cdewolf at redhat.com
Wed Mar 18 03:27:13 EDT 2009


Pete Muir wrote:
>
> On 17 Mar 2009, at 22:29, Carlo de Wolf wrote:
>
> ...
>
>> On another note I would name the SessionObjectReference.getReference 
>> method getBusinessObject (in the likes of 
>> SessionContext.getBusinessObject).
>
> Done
>
>> And both should throw an NoSuchEJBException if the EJB is already 
>> removed.
>
> Done
>
>> (Note: keep the IllegalStateException for invalid businessInterface.)
>
> Not IllegalArgumentException? I went for IllegalArguementException
>
> I also did the changes Ken suggested whilst there...
Well actually I hate both exceptions in this case. I went for 
IllegalStateException, because that's how 
SessionContext.getBusinessObject works, IllegalArgumentException would 
have been the obvious.

I don't entirely agree with Bloch's guidelines for exception handling 
(#1). To me the guideline should be: a checked exception whenever an 
user error is encountered. A precondition on an argument is an user 
error. So NoSuchBusinessInterfaceException would have been better.
Then again this leads to ugly coding (#2), so it might even be better to 
add
boolean SessionContext.isBusinessInterface(Class<?> businessInterface);
Then it becomes a programming error again.

Ken, does this argument make sense to you? If so, I'll raise it in EJB-EG.
> ...
>
Carlo

#1: Effective Java Item 40: Use checked exception for recoverable 
conditions and run-time exceptions for programming errors
#2: EJ Item 41: Avoid unnecessary use of checked exceptions



More information about the weld-dev mailing list