From 7ed334915e1ed68b41b13e5823ed031c9264f08a Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 31 Jan 2018 19:50:45 +0100 Subject: [PATCH] Register uncaught exception handler Never miss an exception by using an uncaught exception handler. --- .../java/com/genymobile/scrcpy/ScrCpyServer.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/ScrCpyServer.java b/server/src/main/java/com/genymobile/scrcpy/ScrCpyServer.java index 2e18682a..441fbf8c 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ScrCpyServer.java +++ b/server/src/main/java/com/genymobile/scrcpy/ScrCpyServer.java @@ -36,7 +36,7 @@ public class ScrCpyServer { try { new EventController(device, connection).control(); } catch (IOException e) { - e.printStackTrace(); + Ln.e("Exception from event controller", e); } } }).start(); @@ -52,12 +52,14 @@ public class ScrCpyServer { } public static void main(String... args) throws Exception { + Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + @Override + public void uncaughtException(Thread t, Throwable e) { + Ln.e("Exception on thread " + t, e); + } + }); + Options options = createOptions(args); - try { - scrcpy(options); - } catch (Throwable t) { - t.printStackTrace(); - throw t; - } + scrcpy(options); } }