[rules-dev] Questionable Exception Handling
Mark Proctor
mproctor at codehaus.org
Fri Apr 4 13:55:49 EDT 2008
I don't see a problem with Throwable there? We rethrow again, adding in
some additional information. I found that just catching Exception didn't
work as you could get verification errors and other stuch things. If you
look at the context of that that method is doing too, its using
reflection to instantiate a class.
Mark
Zoltan Farkas wrote:
>
> I was browsing through the drools source code
>
>
>
> I am not a fan of seeing catching Throwable in any java code ...
>
>
>
> I see this in class org.drools.util.ClassUtils:
>
>
>
> /**
>
> * This method will attempt to create an instance of the specified
> Class. It uses
>
> * a syncrhonized HashMap to cache the reflection Class lookup.
>
> * @param className
>
> * @return
>
> */
>
> public static Object instantiateObject(String className) {
>
> Class cls = (Class) ClassUtils.classes.get( className );
>
> if ( cls == null ) {
>
> try {
>
> cls = Class.forName( className );
>
> ClassUtils.classes.put( className, cls );
>
> } catch ( Throwable e ) {
>
> throw new RuntimeException("Unable to load class '" +
> className + "'", e );
>
> }
>
> }
>
>
>
> Object object = null;
>
> try {
>
> object = cls.newInstance();
>
> } catch ( Throwable e ) {
>
> throw new RuntimeException("Unable to instantiate object
> for class '" + className + "'", e );
>
> }
>
> return object;
>
> }
>
>
>
> I believe this masks important errors where the application should not
> continue to run and it would be preferable to crash...
>
>
>
> --zoly
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> rules-dev mailing list
> rules-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-dev/attachments/20080404/ff71ac14/attachment.html
More information about the rules-dev
mailing list