[ox] Remove OxException
All checks were successful
Build / build (push) Successful in 2m52s

This commit is contained in:
Gary Talent 2024-12-14 00:40:05 -06:00
parent ed910c0beb
commit ac7e5be187
2 changed files with 61 additions and 68 deletions

View File

@ -19,7 +19,7 @@ OrganicClawReader::OrganicClawReader(const uint8_t *buff, std::size_t buffSize)
Json::CharReaderBuilder parserBuilder;
auto parser = std::unique_ptr<Json::CharReader>(parserBuilder.newCharReader());
if (!parser->parse(json, json + jsonLen, &m_json, nullptr)) {
throw OxException(1, "Could not parse JSON");
throw ox::Exception(1, "Could not parse JSON");
}
}
@ -27,7 +27,7 @@ OrganicClawReader::OrganicClawReader(const char *json, std::size_t jsonLen) {
Json::CharReaderBuilder parserBuilder;
auto parser = std::unique_ptr<Json::CharReader>(parserBuilder.newCharReader());
if (!parser->parse(json, json + jsonLen, &m_json, nullptr)) {
throw OxException(1, "Could not parse JSON");
throw ox::Exception(1, "Could not parse JSON");
}
}

View File

@ -17,7 +17,7 @@ class exception {
virtual ~exception() = default;
[[nodiscard]]
virtual const char *what() const noexcept {
virtual char const*what() const noexcept {
return "";
}
};
@ -30,64 +30,46 @@ class exception {
#include "typetraits.hpp"
#include "utility.hpp"
#define OxException(...) ox::Exception(__FILE__, __LINE__, __VA_ARGS__)
namespace ox {
using ErrorCode = uint16_t;
struct [[nodiscard]] Error {
const char *msg = nullptr;
const char *file = nullptr;
ox::CString msg = nullptr;
ox::CString file = nullptr;
uint16_t line = 0;
ErrorCode errCode = 0;
constexpr Error() noexcept = default;
explicit constexpr Error(
const char *file,
ox::CString file,
uint32_t const line,
ErrorCode const errCode,
const char *msg = nullptr) noexcept {
this->file = file;
this->line = static_cast<uint16_t>(line);
this->msg = msg;
this->errCode = errCode;
}
ox::CString msg = nullptr) noexcept:
msg{msg},
file{file},
line{static_cast<uint16_t>(line)},
errCode{errCode} {}
explicit constexpr Error(
ErrorCode const errCode,
std::source_location const&src = std::source_location::current()) noexcept {
this->file = src.file_name();
this->line = static_cast<uint16_t>(src.line());
this->errCode = errCode;
}
std::source_location const&src = std::source_location::current()) noexcept:
file{src.file_name()},
line{static_cast<uint16_t>(src.line())},
errCode{errCode}
{}
explicit constexpr Error(
ErrorCode const errCode,
const char *msg,
std::source_location const&src = std::source_location::current()) noexcept {
this->file = src.file_name();
this->line = static_cast<uint16_t>(src.line());
this->msg = msg;
this->errCode = errCode;
}
constexpr Error(const Error &o) noexcept {
this->msg = o.msg;
this->file = o.file;
this->line = o.line;
this->errCode = o.errCode;
}
constexpr Error &operator=(const Error &o) noexcept {
this->msg = o.msg;
this->file = o.file;
this->line = o.line;
this->errCode = o.errCode;
return *this;
}
ox::CString msg,
std::source_location const&src = std::source_location::current()) noexcept:
msg{msg},
file{src.file_name()},
line{static_cast<uint16_t>(src.line())},
errCode{errCode}
{}
constexpr operator uint64_t() const noexcept {
return errCode;
@ -96,51 +78,62 @@ struct [[nodiscard]] Error {
};
[[nodiscard]]
constexpr auto errCode(const Error &err) noexcept {
constexpr auto errCode(Error const&err) noexcept {
return err.errCode;
}
template<typename T=const char*>
template<typename T = char const*>
[[nodiscard]]
constexpr auto toStr(const Error &err) noexcept {
return err.msg ? T(err.msg) : "";
constexpr auto toStr(Error const&err) noexcept {
return err.msg ? T{err.msg} : "";
}
struct Exception: public std::exception {
const char *msg = nullptr;
const char *file = nullptr;
ox::CString msg = nullptr;
ox::CString file = nullptr;
uint16_t line = 0;
ErrorCode errCode = 0;
explicit inline Exception(const char *file, uint32_t line, ErrorCode errCode, const char *msg = "") noexcept {
explicit inline Exception(ox::CString file, uint32_t line, ErrorCode errCode, char const*msg = "") noexcept {
this->file = file;
this->line = static_cast<uint16_t>(line);
this->msg = msg;
this->errCode = errCode;
}
explicit inline Exception(const Error &err) {
if (err.msg) {
this->msg = err.msg;
} else {
this->msg = "";
}
this->file = err.file;
this->line = err.line;
this->errCode = err.errCode;
}
explicit inline Exception(
ErrorCode const errCode,
std::source_location const&src = std::source_location::current()) noexcept:
file{src.file_name()},
line{static_cast<uint16_t>(src.line())},
errCode{errCode} {}
explicit inline Exception(
ErrorCode const errCode,
ox::CString msg,
std::source_location const&src = std::source_location::current()) noexcept:
msg{msg},
file{src.file_name()},
line{static_cast<uint16_t>(src.line())},
errCode{errCode} {}
explicit inline Exception(Error const&err) noexcept:
msg{err.msg ? err.msg : ""},
file{err.file},
line{err.line},
errCode{err.errCode} {}
constexpr Error toError() const noexcept {
return Error(file, line, errCode, msg);
}
[[nodiscard]]
const char *what() const noexcept override {
char const*what() const noexcept override {
return msg;
}
};
void panic(const char *file, int line, const char *panicMsg, const Error &err) noexcept;
void panic(char const*file, int line, char const*panicMsg, Error const&err) noexcept;
template<typename T>
struct [[nodiscard]] Result {
@ -154,25 +147,25 @@ struct [[nodiscard]] Result {
}
template<typename U>
constexpr Result(const Result<U> &other) noexcept: value(other.value), error(other.error) {
constexpr Result(Result<U> const&other) noexcept: value(other.value), error(other.error) {
}
template<typename U>
constexpr Result(Result<U> &&other) noexcept: value(std::move(other.value)), error(std::move(other.error)) {
}
constexpr Result(const Error &error) noexcept: value(), error(error) {
constexpr Result(Error const&error) noexcept: value(), error(error) {
}
constexpr Result(const type &value, const Error &error = ox::Error(0)) noexcept: value(value), error(error) {
constexpr Result(type const&value, Error const&error = {}) noexcept: value(value), error(error) {
}
constexpr Result(type &&value, const Error &error = ox::Error(0)) noexcept: value(std::move(value)), error(error) {
constexpr Result(type &&value, Error const&error = {}) noexcept: value(std::move(value)), error(error) {
}
constexpr ~Result() noexcept = default;
explicit constexpr operator const type&() const noexcept {
explicit constexpr operator type const&() const noexcept {
return value;
}
@ -341,18 +334,18 @@ struct [[nodiscard]] Result {
namespace detail {
constexpr Error toError(const Error &e) noexcept {
constexpr Error toError(Error const&e) noexcept {
return e;
}
template<typename T>
constexpr Error toError(const Result<T> &r) noexcept {
constexpr Error toError(Result<T> const&r) noexcept {
return r.error;
}
}
constexpr void primitiveAssert(const char *file, int line, bool pass, const char *msg) noexcept {
constexpr void primitiveAssert(char const*file, int line, bool pass, char const*msg) noexcept {
if constexpr(ox::defines::Debug) {
if (!pass) [[unlikely]] {
panic(file, line, msg, ox::Error(1));