Skip to content

Instantly share code, notes, and snippets.

@relistan
Created April 29, 2016 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save relistan/06726b9a4b5696c043ad1bd652992cce to your computer and use it in GitHub Desktop.
Save relistan/06726b9a4b5696c043ad1bd652992cce to your computer and use it in GitHub Desktop.
logback_test.java
package hello;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyApp1 {
final static Logger logger = LoggerFactory.getLogger(MyApp1.class);
private static void setDefaultUncaughtExceptionHandler() {
try {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
logger.error("Something REALLY went wrong", e);
}
});
} catch (SecurityException e) {
logger.error("Could not set the Default Uncaught Exception Handler", e);
}
}
public static void main(String[] args) throws Exception {
setDefaultUncaughtExceptionHandler();
logger.info("Entering application.");
logger.info("About to throw from application.");
try {
throw new Exception("Oh no!");
} catch(Exception e) {
logger.error("Something went wrong", e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment