geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Adrian Jackson" <>
Subject RE: [Error handling] NullPointer or IllegalArgument?
Date Thu, 14 Aug 2003 14:14:19 GMT
Alex Blewitt wrote:
> What I was saying is that NPE is an exception a programmer should
> never throw, and if checked exceptions or other suitable exceptions
> (IAE, NAE) don't allow, then throw RuntimeException instead of NPE.

I'm strongly inclined to agree with *both* of you. Never throw
RuntimeException. Never throw NullPointerException. If you find yourself
thinking it would be a good idea to throw either of these, then have a
stiff drink and write a new exception class (not necessarily in that

If either is acceptable, then it's probably the use of the
NullPointerException, since the API documentation says "Applications
should throw instances of this class to indicate other illegal uses of
the null object", whereas for RuntimeException it says "RuntimeException
is the *superclass* of those exceptions that can be thrown during the
normal operation of the Java Virtual Machine" (my emphasis).

But really, neither is a good idea in my book, for the reasons that Alex
and Berin point out.

And I'd also add my +1 to the idea that we should never have have a
catch block for type Exception, except with very good reason.


View raw message