Working error system I believe

This commit is contained in:
NaifBanana
2025-11-09 23:36:12 -06:00
parent 9024cce1b4
commit c2cdfe7052
3 changed files with 76 additions and 28 deletions
+8 -6
View File
@@ -5,7 +5,9 @@ using namespace nb;
class TestError : public ErrorBase<TestError> {
public:
TestError(unsigned int code, std::exception* const trace=nullptr)
TestError(unsigned int code)
: ErrorBase<TestError>(code, ErrorBase<TestError>::lookup(code)) {}
TestError(unsigned int code, const std::exception& trace)
: ErrorBase<TestError>(code, ErrorBase<TestError>::lookup(code), trace) {}
enum ErrorCodes : unsigned int {
@@ -24,11 +26,11 @@ const ErrorCodeMap TestError::ErrorMessages{
};
int main() {
TestError d(TestError::ErrorCodes::D);
TestError c(TestError::ErrorCodes::C, &d);
TestError b(TestError::ErrorCodes::B, &c);
TestError a(TestError::ErrorCodes::A, &b);
throw Error(Error::ErrorCodes::UNDEFINED, &a);
TestError d(TestError::ErrorCodes::D, std::out_of_range("hey"));
TestError c(TestError::ErrorCodes::C, d);
TestError b(TestError::ErrorCodes::B, c);
TestError a(TestError::ErrorCodes::A, b);
throw Error(Error::ErrorCodes::UNDEFINED, a);
return 0;
}