This commit is contained in:
20
deps/ox/src/ox/std/error.hpp
vendored
20
deps/ox/src/ox/std/error.hpp
vendored
@@ -37,7 +37,7 @@ using ErrorCode = uint16_t;
|
|||||||
|
|
||||||
struct [[nodiscard]] Error {
|
struct [[nodiscard]] Error {
|
||||||
std::source_location src;
|
std::source_location src;
|
||||||
ox::CString msg = nullptr;
|
CString msg = nullptr;
|
||||||
ErrorCode errCode = 0;
|
ErrorCode errCode = 0;
|
||||||
|
|
||||||
constexpr Error() noexcept = default;
|
constexpr Error() noexcept = default;
|
||||||
@@ -51,7 +51,7 @@ struct [[nodiscard]] Error {
|
|||||||
|
|
||||||
explicit constexpr Error(
|
explicit constexpr Error(
|
||||||
ErrorCode const errCode,
|
ErrorCode const errCode,
|
||||||
ox::CString msg,
|
CString const msg,
|
||||||
std::source_location const &src = std::source_location::current()) noexcept:
|
std::source_location const &src = std::source_location::current()) noexcept:
|
||||||
src{src},
|
src{src},
|
||||||
msg{msg},
|
msg{msg},
|
||||||
@@ -62,6 +62,18 @@ struct [[nodiscard]] Error {
|
|||||||
return errCode;
|
return errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr Error reoriginate(
|
||||||
|
ErrorCode const pErrCode,
|
||||||
|
CString const pMsg = nullptr,
|
||||||
|
std::source_location const &pSrc = std::source_location::current()) const noexcept {
|
||||||
|
return Error{pErrCode, pMsg, pSrc};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Error reoriginate(
|
||||||
|
std::source_location const &pSrc = std::source_location::current()) const noexcept {
|
||||||
|
return Error{errCode, msg, pSrc};
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
@@ -112,13 +124,13 @@ struct Exception: public std::exception {
|
|||||||
[[noreturn]]
|
[[noreturn]]
|
||||||
void panic(
|
void panic(
|
||||||
Error const &err,
|
Error const &err,
|
||||||
char const *panicMsg,
|
CString panicMsg,
|
||||||
std::source_location const &src = std::source_location::current()) noexcept;
|
std::source_location const &src = std::source_location::current()) noexcept;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct [[nodiscard]] Result {
|
struct [[nodiscard]] Result {
|
||||||
|
|
||||||
using type = typename remove_reference<T>::type;
|
using type = remove_reference_t<T>;
|
||||||
|
|
||||||
T value;
|
T value;
|
||||||
Error error;
|
Error error;
|
||||||
|
|||||||
Reference in New Issue
Block a user