JVM - print trace without explicit invocation

Is there a way in java to print a stack trace of any exception in a catch block without making code changes. I was told that there is a JVM arg that you could use to create stack traces of all exceptions for debugging, although I cannot find any documentation on this. The only solution I can come up with for this is to use aspectj and create an aspect for any exception that is thrown and print a stack trace. I was hoping there was a better solution than aspects.

Thanks Steve.

- Edit-- So what I want to know is to say that I have this code: try {throw new Exception (); } catch (Exception e) {// Ignore exceptions}

I would like to see e.printStackTrace (), even though they do not call him. This can help in debugging the jvm crash that I see and there is a lot of error hiding going on.

+3
source share
2 answers

As Marco Topolnik said, registering any exception can take a bit of work, but you can also implement your own exception exception handler to do whatever you want 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);
    }
});
+2
source

. , . Throwable, . , , .

0

All Articles