This code is from our project, production code:
if (changedToNull) {
try {
throw new Exception();
} catch (Exception e) {
log.debug("changedToNull", e);
}
}
The developer does not work with us any more.
Why would someone throw an Exception and catch directly and log it?
The main purpose is to get a call stack when you enter in this if block for debugging purpose but it could be rewritten as next:
if (changedToNull) {
log.debug("changedToNull", new Exception("changedToNull is true"));
}
Let's say that changedToNull should never be true and you want to get the call stack to understand how it occurred, you could proceed this way.
Creating a call stack is quite expensive so you should make sure that the debug level is enabled by checking the value of isDebugEnabled() too (assuming that you use log4j) as next:
if (changedToNull && log.isDebugEnabled()) {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With