Return-Path: Delivered-To: apmail-forrest-dev-archive@www.apache.org Received: (qmail 34043 invoked from network); 3 Apr 2006 23:57:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 3 Apr 2006 23:57:26 -0000 Received: (qmail 28612 invoked by uid 500); 3 Apr 2006 23:57:26 -0000 Delivered-To: apmail-forrest-dev-archive@forrest.apache.org Received: (qmail 28444 invoked by uid 500); 3 Apr 2006 23:57:25 -0000 Mailing-List: contact dev-help@forrest.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@forrest.apache.org List-Id: Delivered-To: mailing list dev@forrest.apache.org Received: (qmail 28433 invoked by uid 99); 3 Apr 2006 23:57:25 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Apr 2006 16:57:25 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [212.247.155.1] (HELO swip.net) (212.247.155.1) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Apr 2006 16:57:24 -0700 X-T2-Posting-ID: sqekuHx5EEXz8PMiWfS+nn/CVSJ13AovswB5l38CkqQ= X-Cloudmark-Score: 0.000000 [] Received: from [83.180.137.17] (HELO [192.168.2.5]) by mailfe09.swip.net (CommuniGate Pro SMTP 5.0.8) with ESMTP id 3533744 for dev@forrest.apache.org; Tue, 04 Apr 2006 01:56:55 +0200 Subject: When to catch exceptions (was Re: svn commit: r390198) From: Thorsten Scherler To: Forrest Developers List In-Reply-To: <20060330180517.48821.qmail@minotaur.apache.org> References: <20060330180517.48821.qmail@minotaur.apache.org> Content-Type: text/plain; charset=UTF-8 Date: Tue, 04 Apr 2006 01:56:27 +0200 Message-Id: <1144108587.11958.11.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N El jue, 30-03-2006 a las 18:05 +0000, thorsten@apache.org escribi=C3=B3: > Author: thorsten > Date: Thu Mar 30 10:05:15 2006 > New Revision: 390198 >=20 > URL: http://svn.apache.org/viewcvs?rev=3D390198&view=3Drev > Log: > Testing whether the source exists rather to throw an exception. One shoul= d not throw/catch exception that are predictable. >=20 > Modified: > forrest/trunk/main/java/org/apache/forrest/sourcetype/SourceTypeActio= n.java >=20 > Modified: forrest/trunk/main/java/org/apache/forrest/sourcetype/SourceTyp= eAction.java > URL: http://svn.apache.org/viewcvs/forrest/trunk/main/java/org/apache/for= rest/sourcetype/SourceTypeAction.java?rev=3D390198&r1=3D390197&r2=3D390198&= view=3Ddiff > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- forrest/trunk/main/java/org/apache/forrest/sourcetype/SourceTypeActio= n.java (original) > +++ forrest/trunk/main/java/org/apache/forrest/sourcetype/SourceTypeActio= n.java Thu Mar 30 10:05:15 2006 > @@ -61,10 +61,10 @@ > throw new Exception("SourceTypeAction: src attribute should = be defined and non-empty."); > Source source =3D sourceResolver.resolveURI(src); > XMLPullParser parser =3D new Xerces2(); > - try { > - InputStream is =3D source.getInputStream(); > - parser.setInputSource(new XMLInputSource(null, src, null, is, = null)); > - } catch (SourceNotFoundException e) { > + if (source.exists()) { > + InputStream is =3D source.getInputStream(); > + parser.setInputSource(new XMLInputSource(null, src, null, is= , null)); > + } else { > getLogger().warn("Source '"+source+"' not found"); > return null; > } >=20 We have lots of cases in our code like this example.=20 There are a lot of classes that are rather catching exceptions then prevent to raise them. That is bad and we should remove this whenever possible. Please if you find code like the above in our base send us an enhancement patch. ;) An exception (error) should not be provoced by purpose since it disrupts the processing and is wasting speed. TIA http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html "What Is an Exception? - The Java programming language uses exceptions to provide error-handling capabilities for its programs. An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions." http://www.javaworld.com/javaworld/jw-08-2001/jw-0803-exceptions.html? "The proper use of exceptions can make your programs easier to develop and maintain, freer from bugs, and simpler to use. When exceptions are misused, the opposite situation prevails: programs perform poorly, confuse users, and are harder to maintain." salu2 --=20 thorsten "Together we stand, divided we fall!"=20 Hey you (Pink Floyd)