1#ifndef NEFORCE_CORE_CONFIG_EXCEPTION_HPP__
2#define NEFORCE_CORE_CONFIG_EXCEPTION_HPP__
13NEFORCE_BEGIN_NAMESPACE__
21#define __NEFORCE_ERROR_CONSTRUCTOR(THIS, BASE, INFO) \
22 explicit THIS(const char* info = INFO, const char* type = static_type, const int code = 0) noexcept : \
23 BASE(info, type, code) {} \
25 explicit THIS(const exception& e) : \
28#define __NEFORCE_ERROR_DERIVED_DESTRUCTOR(CLASS) virtual ~CLASS() = default;
30#define __NEFORCE_ERROR_FINAL_DESTRUCTOR(CLASS) ~CLASS() override = default;
32#define __NEFORCE_ERROR_TYPE(CLASS) static constexpr auto static_type = #CLASS;
43#define NEFORCE_ERROR_BUILD_DERIVED_CLASS(THIS, BASE, INFO) \
44 struct THIS : BASE { \
45 __NEFORCE_ERROR_CONSTRUCTOR(THIS, BASE, INFO) \
46 __NEFORCE_ERROR_DERIVED_DESTRUCTOR(THIS) \
47 __NEFORCE_ERROR_TYPE(THIS) \
59#define NEFORCE_ERROR_BUILD_FINAL_CLASS(THIS, BASE, INFO) \
60 struct THIS final : BASE { \
61 __NEFORCE_ERROR_CONSTRUCTOR(THIS, BASE, INFO) \
62 __NEFORCE_ERROR_FINAL_DESTRUCTOR(THIS) \
63 __NEFORCE_ERROR_TYPE(THIS) \
78 static constexpr size_t INFO_SIZE = 256;
79 static constexpr size_t TYPE_SIZE = 48;
81 char info_[INFO_SIZE];
82 char type_[TYPE_SIZE];
96 info_[INFO_SIZE - 1] =
'\0';
97 type_[TYPE_SIZE - 1] =
'\0';
129 other.info_[0] =
'\0';
130 other.type_[0] =
'\0';
144 other.info_[0] =
'\0';
145 other.type_[0] =
'\0';
158 template <
typename Error>
171 NEFORCE_NODISCARD
const char*
what() const noexcept {
return info_; }
177 NEFORCE_NODISCARD
const char*
type() const noexcept {
return type_; }
183 NEFORCE_NODISCARD
int code() const noexcept {
return code_; }
270#if defined(NEFORCE_STATE_DEBUG) || !defined(NDEBUG)
271# define NEFORCE_THROW_EXCEPTION(err) throw_with_stack(err)
273# define NEFORCE_THROW_EXCEPTION(err) throw err
276#define NEFORCE_ASSERTION(COND) \
278 _NEFORCE terminate(); \
283NEFORCE_END_NAMESPACE__
NEFORCE_NODISCARD constexpr T * addressof(T &x) noexcept
获取对象的地址
#define NEFORCE_ERROR_BUILD_FINAL_CLASS(THIS, BASE, INFO)
构建最终异常类宏
#define NEFORCE_ERROR_BUILD_DERIVED_CLASS(THIS, BASE, INFO)
构建可派生的异常类宏
int NEFORCE_API uncaught_exceptions() noexcept NEFORCE_PURE_FUNCTION
未捕获的异常数量
void NEFORCE_API throw_with_stack(const exception &err)
抛出异常并打印堆栈信息
NEFORCE_CONSTEXPR14 void * memory_copy(void *NEFORCE_RESTRICT dest, const void *NEFORCE_RESTRICT src, size_t count) noexcept
从源内存复制到目标内存
constexpr CharT * string_copy(CharT *NEFORCE_RESTRICT dest, const CharT *NEFORCE_RESTRICT src) noexcept
复制字符串
exception & operator=(const exception &other) noexcept
复制赋值运算符
exception(const char *info=static_type, const char *type=static_type, const int code=0)
构造函数
NEFORCE_NODISCARD int code() const noexcept
获取异常码
NEFORCE_NODISCARD const char * type() const noexcept
获取异常类型
exception & operator=(exception &&other) noexcept
移动赋值运算符
virtual ~exception()=default
虚析构函数
NEFORCE_NODISCARD const char * what() const noexcept
获取错误信息
exception(const exception &other) noexcept
复制构造函数
static constexpr auto static_type
静态类型字符串
exception(const Error &error)
模板构造函数
exception(exception &&other) noexcept
移动构造函数