Got logging and errors basically all working the way I want

This commit is contained in:
NaifBanana
2026-06-11 04:24:06 -05:00
parent 0f62aecfa3
commit 58121bdf28
10 changed files with 465 additions and 291 deletions
+32 -3
View File
@@ -3,14 +3,43 @@
#include "Errors.hpp"
#include "Logger.hpp"
class TestError : public nb::Error<TestError> {
using Base = Error<TestError>;
public:
using Base::Base;
using Base::what;
using Base::code;
using Base::msg;
using Base::trace;
enum Codes : unsigned int {
A, B, C, D
};
static const std::string type;
static const nb::ErrorCodeMap ErrorMessages;
};
const std::string TestError::type="TestError";
const nb::ErrorCodeMap TestError::ErrorMessages{
{TestError::Codes::A, "Hey!"},
{TestError::Codes::B, "How"},
{TestError::Codes::C, "You"},
{TestError::Codes::D, "Doin"}
};
int main() {
nb::logger.log("Whoop!");
try {
THROW(nb::Error, "Hiii!");
} catch (nb::Error<nb::NoneType> e){
nb::logger.log("Winner winner chicken dinner!");
THROW(nb::Error(1));
} catch (nb::Error<> e){
nb::logger.log("nb::Error was thrown!");
}
try {
THROW(std::exception());
} catch (std::exception e){
nb::logger.log("std::exception was thrown!");
}
return 0;