Monthly Archives: May 2017

Print java stack trace from anywhere

Need to know which code calls a specific location? Dump the stack trace: 1234import org.apache.commons.lang3.exception.ExceptionUtils; // …somewhere in your method: LOG.trace(ExceptionUtils.getStackTrace(new Throwable())); You’re constructing a Throwable just to capture the current stack — you’re not throwing it. ExceptionUtils.getStackTrace turns the … Continue reading

Posted in java | Leave a comment

Knowing your exception class name

You’re staring at a generic catch (Exception e) and you don’t know which actual exception is being thrown. The trick is to log the runtime class so you can replace the generic catch with a specific one: 12345} catch (Exception … Continue reading

Posted in java | Tagged | Leave a comment