Register uncaught exception handler

Never miss an exception by using an uncaught exception handler.
This commit is contained in:
Romain Vimont 2018-01-31 19:50:45 +01:00
parent 8c4a454d68
commit 7ed334915e
1 changed files with 9 additions and 7 deletions

View File

@ -36,7 +36,7 @@ public class ScrCpyServer {
try { try {
new EventController(device, connection).control(); new EventController(device, connection).control();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Ln.e("Exception from event controller", e);
} }
} }
}).start(); }).start();
@ -52,12 +52,14 @@ public class ScrCpyServer {
} }
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
Options options = createOptions(args); Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
try { @Override
scrcpy(options); public void uncaughtException(Thread t, Throwable e) {
} catch (Throwable t) { Ln.e("Exception on thread " + t, e);
t.printStackTrace();
throw t;
} }
});
Options options = createOptions(args);
scrcpy(options);
} }
} }