From 67f9c9a5b3f74b4927b68fa7c9e48ec38183f56c Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Sun, 4 Feb 2018 22:38:19 -0800 Subject: [PATCH] Fixed TimedRobot.java hanging if an exception was thrown (#926) --- .../main/java/edu/wpi/first/wpilibj/Notifier.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Notifier.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Notifier.java index 89ee1855fa..bfd261c0eb 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Notifier.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Notifier.java @@ -99,6 +99,18 @@ public class Notifier { } }); m_thread.setDaemon(true); + m_thread.setUncaughtExceptionHandler((thread, error) -> { + Throwable cause = error.getCause(); + if (cause != null) { + error = cause; + } + DriverStation.reportError("Unhandled exception: " + error.toString(), error.getStackTrace()); + DriverStation.reportWarning("Robots should not quit, but yours did!", false); + DriverStation.reportError( + "The loopFunc() method (or methods called by it) should have handled " + + "the exception above.", false); + System.exit(1); + }); m_thread.start(); }