File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed
src/main/java/de/doubleslash/keeptime Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ package de .doubleslash .keeptime ;
2+
3+ import java .lang .Thread .UncaughtExceptionHandler ;
4+
5+ import org .slf4j .Logger ;
6+ import org .slf4j .LoggerFactory ;
7+
8+ /**
9+ * Handler logging uncaught exceptions. Gotta Catch 'Em All
10+ *
11+ * @author nmutter
12+ */
13+ public class DefaultExceptionHandler implements UncaughtExceptionHandler {
14+
15+ private final Logger LOG = LoggerFactory .getLogger (this .getClass ());
16+
17+ @ Override
18+ public void uncaughtException (final Thread t , final Throwable e ) {
19+ LOG .error ("Uncaught exception on thread '{}'." , t , e );
20+ }
21+
22+ /**
23+ * Registers this class as default uncaught exception handler
24+ */
25+ public void register () {
26+ LOG .debug ("Registering uncaught exception handler" );
27+ final UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread .getDefaultUncaughtExceptionHandler ();
28+ if (defaultUncaughtExceptionHandler != null ) {
29+ LOG .warn ("Uncaught exception handler was already set ('{}'). Overwritting." , defaultUncaughtExceptionHandler );
30+ }
31+ Thread .setDefaultUncaughtExceptionHandler (this );
32+ }
33+
34+ }
Original file line number Diff line number Diff line change @@ -48,6 +48,9 @@ public class Main extends Application {
4848
4949 @ Override
5050 public void init () throws Exception {
51+ final DefaultExceptionHandler defaultExceptionHandler = new DefaultExceptionHandler ();
52+ defaultExceptionHandler .register ();
53+
5154 springContext = SpringApplication .run (Main .class );
5255 // TODO test if everywhere is used the same model
5356 model = springContext .getBean (Model .class );
You can’t perform that action at this time.
0 commit comments