Difference between revisions of "Java Exception Handling"
Jump to navigation
Jump to search
m |
|||
Line 49: | Line 49: | ||
=== No distinction between exceptions and errors/checked and unchecked exceptions === | === No distinction between exceptions and errors/checked and unchecked exceptions === | ||
Compare | Compare [http://java.sun.com/javase/6/docs/api/java/lang/Exception.html Exception] and [http://java.sun.com/javase/6/docs/api/java/lang/Error.html Error] | ||
== Conclusion == | == Conclusion == | ||
Line 59: | Line 59: | ||
=== Between modules, throw only generic exceptions (e.g. java.lang.Exception, java.lang.RuntimeException) without cause === | === Between modules, throw only generic exceptions (e.g. java.lang.Exception, java.lang.RuntimeException) without cause === | ||
== Links == | |||
[http://www.onjava.com/pub/a/onjava/2003/11/19/exceptions.html OnJava: Best Practices for Exception Handling] |
Revision as of 09:12, 3 November 2008
Problem description[edit]
Modules need dependencies of other modules only because of their exception classes[edit]
From validation/ItemValidating:
String validateItemXml(final String itemXml) throws
ValidationSchemaNotFoundException,
TechnicalException;
From importmanager/ImportHandler:
byte[] doFetch(String sourceName, String identifier) throws FileNotFoundException,
IdentifierNotRecognisedException,
SourceNotAvailableException,
TechnicalException,
FormatNotRecognizedException;
Stacktraces are sometimes swallowed[edit]
try
{
...
}
catch (MalformedURLException e)
{LOGGER.error("Error when replacing regex in fetching URL"); e.printStackTrace(); }
catch(UnsupportedEncodingException e)
{e.printStackTrace();}
try
{
...
}
catch (JiBXException e)
{
e.getCause();
}
Sometimes, excessive stacktraces are shown, even without useful information[edit]
Example from coreservices: File:Exception1.txt
Logger.error, System.out and e.printStackTrace are mixed up happily[edit]
see above