diff --git a/wpilibc/src/main/native/cpp/Notifier.cpp b/wpilibc/src/main/native/cpp/Notifier.cpp index d65ec2555d..d8377527b7 100644 --- a/wpilibc/src/main/native/cpp/Notifier.cpp +++ b/wpilibc/src/main/native/cpp/Notifier.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -95,7 +96,21 @@ Notifier::Notifier(int priority, std::function handler) { // call callback if (handler) { - handler(); + try { + handler(); + } catch (const frc::RuntimeError& e) { + e.Report(); + FRC_ReportError( + err::Error, + "Error in Notifier thread." + " The above stacktrace can help determine where the error " + "occurred.\n" + " See https://wpilib.org/stacktrace for more information.\n"); + throw; + } catch (const std::exception& e) { + HAL_SendError(1, err::Error, 0, e.what(), "", "", 1); + throw; + } } } }); 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 daeaa8835f..25657b398f 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/Notifier.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/Notifier.java @@ -128,10 +128,12 @@ public class Notifier implements AutoCloseable { error = cause; } DriverStation.reportError( - "Unhandled exception: " + error.toString(), error.getStackTrace()); + "Unhandled exception in Notifier thread: " + error.toString(), error.getStackTrace()); DriverStation.reportError( - "The loopFunc() method (or methods called by it) should have handled " - + "the exception above.", + "The Runnable for this Notifier (or methods called by it) should have handled " + + "the exception above.\n" + + " The above stacktrace can help determine where the error occurred.\n" + + " See https://wpilib.org/stacktrace for more information.", false); }); m_thread.start();