On 25/06/10 14:06, christian.muel...@nvoe.at wrote:
> I see to possibilities
> 1) Having our own checked exceptions
> 2) Having no checked exceptions and use runtime exceptions.

I like (2). How about RuntimeException?

> For 2) it would be nice to have our own runtime exception class like
> FeatureAccessRuntimeException. This fastens problem resolution because
> the Stack trace indicates where this exception comes from.

As soon as you wrap exceptions you have lost static type identification 
of exception type and obfuscated detail. You might be adding another 
later of wrapping to an onion.

May I suggest as alternative a utility method that aggregates all the 
detail methods from chained runtime exceptions? Or one that just 
extracts the base cause?

Here is a method I used elsewhere, to get at base causes. I handles the 
special case of SQLException using its own chaining mechanism:

public static String prettyCause(Throwable t) {
     if (t.getCause() != null) {
         return prettyCause(t.getCause());
     } else if (t instanceof SQLException && ((SQLException) 
t).getNextException() != null) {
         return prettyCause(((SQLException) t).getNextException());
     }
     if (t.getMessage() == null) {
         return null;
     } else {
         return t.getMessage().replaceAll("\\s+", " ").trim();
     }
}

Use looks like this:

try {
     o.something(option);
     Constants.LOGGER.info("Did something: " + option.toString());
} catch (Exception e) { // we all hate checked exceptions
     Constants.LOGGER.warn("FAILED to do something: " + option.toString());
     Constants.LOGGER.warn("Cause: " + prettyCause(e));
}

-- 
Ben Caradoc-Davies <ben.caradoc-dav...@csiro.au>
Software Engineering Team Leader
CSIRO Earth Science and Resource Engineering
Australian Resources Research Centre

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to