Return-Path: Delivered-To: apmail-incubator-geronimo-dev-archive@incubator.apache.org Received: (qmail 20462 invoked by uid 500); 14 Aug 2003 14:26:31 -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 20407 invoked from network); 14 Aug 2003 14:26:30 -0000 Received: from onramp.i95.net (205.177.132.17) by daedalus.apache.org with SMTP; 14 Aug 2003 14:26:30 -0000 Received: from apache.org ([66.208.12.130]) by onramp.i95.net (8.12.9/8.12.9) with ESMTP id h7EEQVKx018084 for ; Thu, 14 Aug 2003 10:26:31 -0400 Message-ID: <3F3B9C16.4000205@apache.org> Date: Thu, 14 Aug 2003 10:26:30 -0400 From: Berin Loritsch User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 X-Accept-Language: en-us, en MIME-Version: 1.0 To: geronimo-dev@incubator.apache.org Subject: Re: [Error handling] NullPointer or IllegalArgument? References: <3C364225-CE60-11D7-A6C3-0003934D3EA4@ioshq.com> In-Reply-To: <3C364225-CE60-11D7-A6C3-0003934D3EA4@ioshq.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Alex Blewitt wrote: > >> A typed exception works much better as you can make more specific >> actions if >> necessary. I am not saying to never extend a runtime exception, but I am >> saying don't use it directly. IMNSHO RuntimeException and Exception >> should >> be abstract base classes and not concrete at all. > > > There may well be an argument for that. > > In any case, I wasn't advocating 'Use RuntimeExceptions for all'. I was > saying that there's never a reason to want to use NPE, and if you really > need to throw an unchecked exception (for example, the interface doesn't > allow it) then use a RuntimeException instead. > > Correct me if I misunderstood your post, but it seemed that you assumed > I was advocating RuntimeExceptions for everthing. I wasn't. > RuntimeExceptions are pretty ugly and should be avoided where possible > over another implementation or a checked exception (preferably). > > 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. > :) Actually, I would much rather see an NPE with a message (you can include the name of the parameter in the message) than a generic RuntimeException. The only time an NPE gives you insufficient information is when it is automatically generated--there is no message to clue you in. An NPE communicates that something was null that should not have been, and any supplied message (which I strongly advocate) would give you the hint as to what exactly is wrong. An NPE thrown at the beginning of a method is far easier to test and debug than one thrown by the JVM. You know that code sent a null parameter that wasn't supposed to be sent, so all you have to do is go one step back in the stack trace to see where the culprit really is. If you are adamately opposed to NPEs, then IAE (IllegalArgumentExceptions) are a nice alternative. Either IMO are far better than generic RuntimeExceptions. -- "They that give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." - Benjamin Franklin