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) noexcept : \
25 explicit THIS(const exception& e) : \
28#define __NEFORCE_ERROR_DERIVED_DESTRUCTOR(CLASS) ~CLASS() override = default;
30#define __NEFORCE_ERROR_FINAL_DESTRUCTOR(CLASS) ~CLASS() override = default;
32#define __NEFORCE_ERROR_TYPE(CLASS) \
33 NEFORCE_NODISCARD const char* type() const noexcept override { return #CLASS; }
44#define NEFORCE_ERROR_BUILD_DERIVED_CLASS(THIS, BASE, INFO) \
45 struct THIS : BASE { \
46 __NEFORCE_ERROR_CONSTRUCTOR(THIS, BASE, INFO) \
47 __NEFORCE_ERROR_DERIVED_DESTRUCTOR(THIS) \
48 __NEFORCE_ERROR_TYPE(THIS) \
60#define NEFORCE_ERROR_BUILD_FINAL_CLASS(THIS, BASE, INFO) \
61 struct THIS final : BASE { \
62 __NEFORCE_ERROR_CONSTRUCTOR(THIS, BASE, INFO) \
63 __NEFORCE_ERROR_FINAL_DESTRUCTOR(THIS) \
64 __NEFORCE_ERROR_TYPE(THIS) \
79 static constexpr size_t INFO_SIZE = 256;
81 char info_[INFO_SIZE];
91 info_[INFO_SIZE - 1] =
'\0';
117 other.info_[0] =
'\0';
130 other.info_[0] =
'\0';
142 template <
typename Error, enable_if_t<is_base_of_v<exception, Error>,
int> = 0>
155 NEFORCE_NODISCARD
virtual const char*
what() const noexcept {
return info_; }
161 NEFORCE_NODISCARD
virtual const char*
type() const noexcept {
return "exception"; }
180NEFORCE_ERROR_BUILD_FINAL_CLASS(iterator_exception, memory_exception,
"Iterator or Pointer Access Invalid.")
198NEFORCE_ERROR_BUILD_FINAL_CLASS(math_exception, value_exception,
"Math Calculation Invalid.")
228#if (defined(NEFORCE_STATE_DEBUG) || !defined(NDEBUG)) && 0
229# define NEFORCE_THROW_EXCEPTION(err) throw_with_stack(err)
231# define NEFORCE_THROW_EXCEPTION(err) throw err
234#define NEFORCE_ASSERTION(COND) \
236 _NEFORCE terminate(); \
241NEFORCE_END_NAMESPACE__
constexpr T * addressof(T &x) noexcept
获取对象的地址
int uncaught_exceptions() noexcept
未捕获的异常数量
void throw_with_stack(const exception &err)
抛出异常并打印堆栈信息
#define NEFORCE_ERROR_BUILD_DERIVED_CLASS(THIS, BASE, INFO)
构建可派生的异常类宏
constexpr void * memory_copy(void *__restrict dest, const void *__restrict src, size_t count) noexcept
从源内存复制到目标内存
constexpr CharT * string_copy(CharT *__restrict dest, const CharT *__restrict src) noexcept
复制字符串
exception & operator=(const exception &other) noexcept
复制赋值运算符
exception(exception &&other) noexcept
移动构造函数
virtual const char * what() const noexcept
获取错误信息
virtual const char * type() const noexcept
获取异常类型
exception(const exception &other) noexcept
复制构造函数
exception & operator=(exception &&other) noexcept
移动赋值运算符
virtual ~exception()=default
虚析构函数
exception(const Error &error)
模板构造函数
exception(const char *info="")
构造函数