[rules-dev] Questionable Exception Handling

Zoltan Farkas zoly at daxtechnologies.com
Fri Apr 4 12:00:58 EDT 2008


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

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-dev/attachments/20080404/37566b53/attachment.html 


More information about the rules-dev mailing list