You can configure an uncaught-exception handler that will log everything that was created by your application.
In the main method of your Swing application, add the following lines:
Thread.setDefaultUncaughtExceptionHandler(new LoggingExceptionHandler());
System.setProperty("sun.awt.exception.handler", LoggingExceptionHandler.class.getName());
Then we implement the exception handler as follows:
package com.initech.tps;
import java.lang.Thread.UncaughtExceptionHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LoggingExceptionHandler implements UncaughtExceptionHandler
{
private static final Logger logger = LoggerFactory.getLogger(LoggingExceptionHandler.class);
@Override
public void uncaughtException(Thread t, Throwable e)
{
logger.error("caught exception in thread: " + t.getName(), e);
}
}
source
share