[ox/std] Add implementation of what() to ox::Exception

This commit is contained in:
Gary Talent 2021-10-14 19:20:46 -05:00
parent 853f8c25ea
commit 160ef61520

View File

@ -12,7 +12,15 @@
#include <exception> #include <exception>
#else #else
namespace std { namespace std {
class exception {}; class exception {
public:
virtual ~exception() = default;
[[nodiscard]]
virtual const char *what() const noexcept {
return "";
}
};
} }
#endif #endif
@ -22,6 +30,7 @@ class exception {};
#include "utility.hpp" #include "utility.hpp"
#define OxError(...) ox::Error(__FILE__, __LINE__, __VA_ARGS__) #define OxError(...) ox::Error(__FILE__, __LINE__, __VA_ARGS__)
#define OxException(...) ox::Error(__FILE__, __LINE__, __VA_ARGS__)
namespace ox { namespace ox {
@ -71,12 +80,28 @@ struct Exception: public std::exception {
uint16_t line = 0; uint16_t line = 0;
ErrorCode errCode = 0; ErrorCode errCode = 0;
explicit inline Exception(const char *file, uint32_t line, ErrorCode errCode, const char *msg = nullptr) noexcept {
this->file = file;
this->line = line;
this->msg = msg;
this->errCode = errCode;
}
inline explicit Exception(const Error &err) { inline explicit Exception(const Error &err) {
this->msg = err.msg; this->msg = err.msg;
this->file = err.file; this->file = err.file;
this->line = err.line; this->line = err.line;
this->errCode = err.errCode; this->errCode = err.errCode;
} }
constexpr Error toError() const noexcept {
return Error(file, line, errCode, msg);
}
[[nodiscard]]
const char *what() const noexcept override {
return msg;
}
}; };
template<typename T> template<typename T>