On Wed, Aug 3, 2011 at 4:30 PM, Rickard Öberg <[email protected]> wrote:
> In the current API we have a number of methods that return null, and so the
> client has to do null checks before continuing. One example would be
> descriptor access methods in the Qi4j API class. Same with
> currentUnitOfWork().
>
> I suggest that all of these are changed to throw IllegalArgumentException or
> IllegalStateException (according to what makes sense) instead, so that
> client code can rely on objects being returned correctly in the "normal
> case".

Well, is it effectively any better to get such an Exception served than an NPE??

Returning 'null' at least allows the client to "recover", for instance
what is happening in UnitOfWorkPropagation, which otherwise will have
an "expensive" exception thrown in many cases...

I would in that case prefer to return a InvalidXyz object which can be
inspected to be 'invalid' and if you still use it the exception is
thrown.


Cheers
-- 
Niclas Hedhman, Software Developer
http://www.qi4j.org - New Energy for Java

I live here; http://tinyurl.com/3xugrbk
I work here; http://tinyurl.com/24svnvk
I relax here; http://tinyurl.com/2cgsug

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to