El jue, 30-03-2006 a las 18:05 +0000, [EMAIL PROTECTED] escribió: > Author: thorsten > Date: Thu Mar 30 10:05:15 2006 > New Revision: 390198 > > URL: http://svn.apache.org/viewcvs?rev=390198&view=rev > Log: > Testing whether the source exists rather to throw an exception. One should > not throw/catch exception that are predictable. > > Modified: > > forrest/trunk/main/java/org/apache/forrest/sourcetype/SourceTypeAction.java > > Modified: > forrest/trunk/main/java/org/apache/forrest/sourcetype/SourceTypeAction.java > URL: > http://svn.apache.org/viewcvs/forrest/trunk/main/java/org/apache/forrest/sourcetype/SourceTypeAction.java?rev=390198&r1=390197&r2=390198&view=diff > ============================================================================== > --- > forrest/trunk/main/java/org/apache/forrest/sourcetype/SourceTypeAction.java > (original) > +++ > forrest/trunk/main/java/org/apache/forrest/sourcetype/SourceTypeAction.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 = sourceResolver.resolveURI(src); > XMLPullParser parser = new Xerces2(); > - try { > - InputStream is = source.getInputStream(); > - parser.setInputSource(new XMLInputSource(null, src, null, is, > null)); > - } catch (SourceNotFoundException e) { > + if (source.exists()) { > + InputStream is = source.getInputStream(); > + parser.setInputSource(new XMLInputSource(null, src, null, is, > null)); > + } else { > getLogger().warn("Source '"+source+"' not found"); > return null; > } >
We have lots of cases in our code like this example. 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 -- thorsten "Together we stand, divided we fall!" Hey you (Pink Floyd)
