Skip to content

Instantly share code, notes, and snippets.

@davidallsopp
Created February 17, 2014 13:55
Show Gist options
  • Save davidallsopp/9050955 to your computer and use it in GitHub Desktop.
Save davidallsopp/9050955 to your computer and use it in GitHub Desktop.
Handling otherwise-unhandled exceptions in a thread. See the javadoc for Thread.setUncaughtExceptionHandler(): "Set the handler invoked when this thread abruptly terminates due to an uncaught exception. A thread can take full control of how it responds to uncaught exceptions by having its uncaught exception handler explicitly set. If no such han…
Thread t = new Thread() {
public void run() {
// do something useful
}
};
t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
public void uncaughtException(Thread exThread, Throwable ex) {
// handle it here
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment