On Jul 17, 2013, at 8:55 PM, Gary Gregory wrote:

> Hi all,
> 
> If you scan the source for all senders of "printStackTrace" you'll find  21 
> references.
> 
> Are all of those correct instead of logging to StatusLogger or throwing an 
> exception

I would say "none of them are correct." Outside of testing, I can think of 
exactly zero reasons where you would ever want to call printStackTrace in a 
library or non-console application. They should all go away, IMO.

> or a different exception in the case where this is done in response to 
> catching an exception.
> 
> Also, in some cases like 
> org.apache.logging.log4j.ReflectionComparison.setupCallerCheck(), both are 
> done:
> 
>         } catch (final ClassNotFoundException cnfe) {
>             cnfe.printStackTrace();
>             throw new RuntimeException(cnfe);
>         }
> 
> In this case, should we not call StatusLogger?
> 
> I'd also rather never throw a RuntimeException, instead an 
> IllegalStateException.
> 
> Also, this method is undocumented and uses a dynamic reference to the Java 7 
> sun.reflect.Reflection class. How is that going to work on an IBM JVM?

It's not. I don't know what ReflectionComparison does, so perhaps someone else 
can shed some light on it. I know that ThrowableProxy also uses 
sun.reflect.Reflection, but that's for optimization and it has a "back-up plan" 
that activates if sun.reflect.Reflection doesn't exist.

> 
> Gary
> 
> 
> -- 
> E-Mail: [email protected] | [email protected] 
> Java Persistence with Hibernate, Second Edition
> JUnit in Action, Second Edition
> Spring Batch in Action
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory

Reply via email to