mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[wpilibc] Add C++ Notifier error handling, update java notifier error message (#4795)
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <utility>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <hal/DriverStation.h>
|
||||
#include <hal/FRCUsageReporting.h>
|
||||
#include <hal/Notifier.h>
|
||||
#include <hal/Threads.h>
|
||||
@@ -95,7 +96,21 @@ Notifier::Notifier(int priority, std::function<void()> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user