Return-Path: Delivered-To: apmail-incubator-geronimo-dev-archive@incubator.apache.org Received: (qmail 83156 invoked by uid 500); 14 Aug 2003 14:14:19 -0000 Mailing-List: contact geronimo-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: geronimo-dev@incubator.apache.org Delivered-To: mailing list geronimo-dev@incubator.apache.org Received: (qmail 83087 invoked from network); 14 Aug 2003 14:14:18 -0000 Received: from unknown (HELO mail.dynamicweb.co.uk) (213.219.6.66) by daedalus.apache.org with SMTP; 14 Aug 2003 14:14:18 -0000 content-class: urn:content-classes:message Subject: RE: [Error handling] NullPointer or IllegalArgument? Date: Thu, 14 Aug 2003 15:14:19 +0100 Message-ID: <77C686785CD8324998F642387A94F740324DC3@tobermory2.dynamicweb.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: [Error handling] NullPointer or IllegalArgument? X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 Thread-Index: AcNibSTeAw4yITSASjC7EH2bI5RQTgAAGJ4A From: "Adrian Jackson" To: X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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 order). 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. Adrian