Is there a way in java to print a stack trace of any exception in a catch block without making code modifications. I was told that there was a JVM arg you could use to produce stack traces of all exceptions for debugging, although I can't find any documentation on this. The only solution I can think of for this is to use aspectj and create an aspect on any exception that is created and print the stack trace. I was hoping there was a better solution than aspects.
Thanks, Steve.
--Edit-- So what I want to find out is lets say I have this code: try { throw new Exception(); } catch (Exception e) { //Ignore exceptions }
I would like to see the e.printStackTrace() even though no call is made to it. This can help with debugging a jvm crash I am seeing, and there is a lot of error hiding going on.
As Marko Topolnik said, logging any exception may take a bit of work, but you can also implement a custom uncaught exception handler to do whatever you please with uncaught exceptions.
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
private final Logger log = Logger.getLogger("EXCEPTION");
public void uncaughtException(final Thread t, final Throwable e) {
log.logp(Level.SEVERE, "EXCEPTION", "", "Unhandled exception in thread " + t.getName() + ": ", e);
}
});
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