[wpilibc] Remove ErrorBase (#3306)

Replace with new exception-based error reporting, consistent with Java.
This also builds stacktraces into the reporting/exceptions.
This commit is contained in:
Peter Johnson
2021-04-18 20:35:29 -07:00
committed by GitHub
parent 0abf6c9045
commit 8d961dfd25
113 changed files with 993 additions and 2200 deletions

View File

@@ -10,7 +10,7 @@
#include <wpi/StringMap.h>
#include <wpi/mutex.h>
#include "frc/WPIErrors.h"
#include "frc/Errors.h"
#include "frc/smartdashboard/SendableRegistry.h"
using namespace frc;
@@ -85,9 +85,8 @@ nt::NetworkTableEntry SmartDashboard::GetEntry(wpi::StringRef key) {
}
void SmartDashboard::PutData(wpi::StringRef key, Sendable* data) {
if (data == nullptr) {
wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
return;
if (!data) {
throw FRC_MakeError(err::NullParameter, "value");
}
auto& inst = Singleton::GetInstance();
std::scoped_lock lock(inst.tablesToDataMutex);
@@ -103,9 +102,8 @@ void SmartDashboard::PutData(wpi::StringRef key, Sendable* data) {
}
void SmartDashboard::PutData(Sendable* value) {
if (value == nullptr) {
wpi_setGlobalWPIErrorWithContext(NullParameter, "value");
return;
if (!value) {
throw FRC_MakeError(err::NullParameter, "value");
}
auto name = SendableRegistry::GetInstance().GetName(value);
if (!name.empty()) {
@@ -118,8 +116,7 @@ Sendable* SmartDashboard::GetData(wpi::StringRef key) {
std::scoped_lock lock(inst.tablesToDataMutex);
auto it = inst.tablesToData.find(key);
if (it == inst.tablesToData.end()) {
wpi_setGlobalWPIErrorWithContext(SmartDashboardMissingKey, key);
return nullptr;
throw FRC_MakeError(err::SmartDashboardMissingKey, key);
}
return SendableRegistry::GetInstance().GetSendable(it->getValue());
}