geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Blewitt <Alex.Blew...@ioshq.com>
Subject Re: [Error handling] NullPointer or IllegalArgument?
Date Thu, 14 Aug 2003 17:46:41 GMT
On Thursday, Aug 14, 2003, at 18:17 Europe/London, Berin Loritsch wrote:

> Alex Blewitt wrote:
>
>> Why bother? RuntimeException has an argument to pass in the exception 
>> type to the superclass ...
> Clarity.  For the same reason that you complained about not being able
> to differentiate between an NPE thrown by the system and one thrown by
> our code.  You can't differentiate a RuntimeException that holds an
> IOException and one that holds a SQLException if all you use are
> RuntimeExceptions.
>
> New exception types don't need to all be thought up in advance.  You 
> can
> create them as you find you have need.

The question is, do you really need to be able to catch both exception 
types distinctly? You can instead use:

} (catch RuntimeException e) {
   Throwable cause = e.getCause();
   if (cause instanceof IOException) {
   } else if (cause instanceof SQLException) {
   } ...
}

I think this topic has had enough open airing in this mailing list now 
anyway, and whilst (hopefully) it's provoked a few thoughts, the 
general advice of not using RuntimeException and NullPointerException, 
and the benefits of using IllegalArgumentException and 
NullArgumentException have probably gone through, which was the 
original intent :-)

I'd be happy to take the discussion off-line and further bash out a few 
points if you'd like to continue talking about it, though :-)

Alex.


Mime
View raw message