Error Handling#
Entix’s main way to handle errors is Entix::Result. This class are inspired by Rust’s Result
and doing same things.
Recovarable errors#
Header file:
#include <Entix/Core/Result.h>
-
class Error#
Error base class.
Mainly implemented for using in Result class. You can also use it for throw/try/catch statements.
-
template<typename SuccessType, typename ErrorType = Error>
class Result# Rust-like Result type.
Public Functions
-
inline EX_FORCE_INLINE constexpr Result(const SuccessType &value)#
-
inline EX_FORCE_INLINE constexpr Result(SuccessType &&value)#
-
inline bool IsSuccess() const noexcept#
-
inline bool IsError() const noexcept#
-
inline explicit operator bool() const noexcept#
-
inline SuccessType Unwrap(std::source_location location = std::source_location::current()) const#
-
inline SuccessType Unwrap(std::source_location location = std::source_location::current()) const
-
inline ErrorType UnwrapErr(std::source_location location = std::source_location::current()) const
-
inline EX_FORCE_INLINE constexpr Result(const SuccessType &value)#
-
EX_TRY(EXPR)#
Try to execute the resulting expression.
Usage Example:
extern Result<void> AnotherResultingFn(); Result<void> SomeFn() { EX_TRY(AnotherResultingFn()); return {}; }
-
EX_LET_TRY(VAR, EXPR)#
Try to execute the resulting expression and if it success save unwrapped result to variable.
Usage Example:
extern Result<int> AnotherResultingFn(); Result<int> SomeFn() { EX_LET_TRY(code, AnotherResultingFn()); return code; // It returns `AnotherResultingFn()` result if it successfuly executed }
Unrecovarable errors#
Header file:
#include <Entix/Core/Panic.h>
Note
In Debug build Entix::Panic() also place debug breakpoint
-
void Entix::Panic(std::source_location location = std::source_location::current())#
Throw unrecovarable error.
- Parameters:
location – [in] Source location. Used only in debug purposes, you shouldn’t override default value!
- Throws:
std::runtime_error – Runtime error which are catched by entry point and closes application after that.
-
void Entix::Panic(StringView message, std::source_location location = std::source_location::current())#
Throw unrecovarable error with message.
- Parameters:
message – [in] This message will be saved in logs
location – [in] Source location. Used only in debug purposes, you shouldn’t override default value!
- Throws:
std::runtime_error – Runtime error which are catched by entry point and closes application after that.
Assertions#
Header file:
#include <Entix/Core/Assert.h>
Assertions just checking provided expression and if it evaluated to false call the Entix::Panic()
with custom message.
Attention
Assertion macro are enabled only in Debug build!
-
EX_ASSERT(EXPR)#
-
EX_ASSERT_FMT(EXPR, FMT, ...)#
Assertion with custom message.
Usage example:
void SoUnstableThing() { EX_ASSERT_FMT(false, "Hello, {}!", "World"); }
- Parameters:
EXPR – [in] Expression to check
FMT – [in] Format string
... – [in] Format args (if necessary)
- Throws std::runtime_error:
See