Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 61527 invoked from network); 21 Aug 2002 20:48:19 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 21 Aug 2002 20:48:19 -0000 Received: (qmail 28903 invoked by uid 97); 21 Aug 2002 20:48:47 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 28887 invoked by uid 97); 21 Aug 2002 20:48:47 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 28874 invoked by uid 98); 21 Aug 2002 20:48:46 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Reply-To: From: "Steven Caswell" To: "'Jakarta Commons Developers List'" Subject: RE: [commons]NPE or IAE? Date: Wed, 21 Aug 2002 16:48:11 -0400 Message-ID: <003401c24954$103f4e60$2c00a8c0@YellowJacket> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 In-Reply-To: X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Importance: Normal X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N I tend to agree with Michael's observations about using different exceptions. It has been my experience is that using different exceptions to indicate different conditions is preferred (and IMHO these are different conditions). This presents the most flexibility to the caller. Steven Caswell steven@caswell.name a.k.a Mungo Knotwise of Michel Delving "One ring to rule them all, one ring to find them..." > -----Original Message----- > From: Michael A. Smith [mailto:mas@apache.org] > Sent: Wednesday, August 21, 2002 3:42 PM > To: Jakarta Commons Developers List; Ola Berg > Subject: Re: [commons]NPE or IAE? > > > On Wed, 21 Aug 2002, Ola Berg wrote: > > > A quickie. > > > > When contributing new code directly to Commons, would you > like me to > > use IllegalArgumentException for all illegal arguments to a > method, or > > NullPointerException for the illegal nulls? > > > > This question goes out to > > 1) all Commons, since this is fresh code in Commons > > 2) io, since the particular class is in io > > 3) lang, since it works closely with lang > > > > Preferences, anybody? > > my preference is for both. If an argument is not valid (e.g. > passing in > a negative number when a positive is expected), throw an > IllegalArgumentException. If there's a null when an object > is expecte,d > throw a NullPointerException. > > > Personally, I prefer IAE, since that leaves me with only > one exception > > to throw for all illegal arguments, regardless of cause. > Putting the > > right value in a parameter is something you do in order to maintain > > consistency, avoiding NPE and other runtime exceptions. IMO. > > But distinguishing the cause can be important. Different > exceptions for > different exceptional conditions. > > NullPointerException - "Applications should throw instances > of this class to indicate other illegal uses of the null object." > > IllegalArgumentException implies that an argument was supplied and > illegal (different than not being supplied at all, as in a > null object): > "Thrown to indicate that a method has been passed an illegal or > inappropriate argument." > > > Second: there was a thread on coding conventions lately. I > wonder if > > it would be a benefit if questions like these (such as naming > > conventions: XxxUtils/Xxxs, when to use toXxx and when to use asXxx > > etc) could be answered in a \"prefered style\" document: a > non binding > > style guide that reflects the most popular styles of the > committers, > > or lists the acceptable styles (sorted in order of > preference maybe)? > > > > IIRC, XxxUtils was favored over Xxxs by the majority, but was that > > documented (elsewhere than in the mails)? In a document where the > > answer to the NPE/IAE question should go too? > > the XxxUtils over Xxxs was documented for the collections component: > http://cvs.apache.org/viewcvs/*checkout*/jakarta-commons/collections/DEV ELOPERS-GUIDE.html regards, michael -- To unsubscribe, e-mail: For additional commands, e-mail: -- To unsubscribe, e-mail: For additional commands, e-mail: