[rules-dev] Questionable Exception Handling
Geoffrey Wiseman
geoffrey.wiseman at gmail.com
Fri Apr 4 14:09:38 EDT 2008
In most cases, I'd say that Errors shouldn't even be caught and rethrown,
personally -- something like an OOME doesn't need additional object
creation, for instance.
On Fri, Apr 4, 2008 at 1:55 PM, Mark Proctor <mproctor at codehaus.org> wrote:
> 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 listrules-dev at lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-dev
>
>
>
> _______________________________________________
> rules-dev mailing list
> rules-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-dev
>
>
--
Geoffrey Wiseman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-dev/attachments/20080404/e25c4fa4/attachment.html
More information about the rules-dev
mailing list