MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
异常处理

MSTL异常处理类与工具 更多...

异常处理 的协作图:

专题

 异常类集
 MSTL异常类集

class  exception_wrapper
 异常包装器基类 更多...
class  typed_exception_wrapper< Ex >
 类型化异常包装器模板类 更多...
class  exception_ptr
 异常指针类 更多...
struct  exception_ptr::ecb
 异常控制块 更多...

宏定义

#define MSTL_ERROR_BUILD_DERIVED_CLASS(THIS, BASE, INFO)
 构建可派生的异常类宏
#define MSTL_ERROR_BUILD_FINAL_CLASS(THIS, BASE, INFO)
 构建最终异常类宏

函数

void MSTL_API throw_with_stack (const exception &err)
 抛出异常并打印堆栈信息
virtual void exception_wrapper::rethrow () const =0
 重新抛出异常
virtual const std::type_info & exception_wrapper::type () const noexcept=0
 获取异常类型信息
virtual unique_ptr< exception_wrapperexception_wrapper::clone () const =0
 克隆异常包装器
 typed_exception_wrapper< Ex >::typed_exception_wrapper (const Ex &ex)
 拷贝构造函数
 typed_exception_wrapper< Ex >::typed_exception_wrapper (Ex &&ex) noexcept
 移动构造函数
MSTL_ALWAYS_INLINE void typed_exception_wrapper< Ex >::rethrow () const override
 重新抛出异常
MSTL_ALWAYS_INLINE const std::type_info & typed_exception_wrapper< Ex >::type () const noexcept override
 获取异常类型信息
MSTL_ALWAYS_INLINE unique_ptr< exception_wrappertyped_exception_wrapper< Ex >::clone () const override
 克隆异常包装器
 exception_ptr::ecb::ecb (unique_ptr< exception_wrapper > wrapper)
 构造函数
MSTL_ALWAYS_INLINE void exception_ptr::ecb::add_ref () noexcept
 增加引用计数
MSTL_ALWAYS_INLINE void exception_ptr::ecb::release () noexcept
 减少引用计数
 exception_ptr::exception_ptr (nullptr_t np=nullptr) noexcept
 默认构造函数
 exception_ptr::exception_ptr (const exception_ptr &other) noexcept
 拷贝构造函数
 exception_ptr::exception_ptr (exception_ptr &&other) noexcept
 移动构造函数
 exception_ptr::~exception_ptr () noexcept
 析构函数
exception_ptrexception_ptr::operator= (const exception_ptr &other) noexcept
 拷贝赋值运算符
exception_ptrexception_ptr::operator= (exception_ptr &&other) noexcept
 移动赋值运算符
void exception_ptr::swap (exception_ptr &other) noexcept
 交换两个异常指针
 exception_ptr::operator bool () const noexcept
 布尔转换运算符
bool exception_ptr::operator== (const exception_ptr &rhs) const noexcept
 相等比较运算符
bool exception_ptr::operator!= (const exception_ptr &rhs) const noexcept
 不等比较运算符
bool exception_ptr::operator== (nullptr_t) const noexcept
 与空指针比较相等
bool exception_ptr::operator!= (nullptr_t) const noexcept
 与空指针比较不等
MSTL_NODISCARD const std::type_info & exception_ptr::exception_type () const noexcept
 获取异常类型信息
template<typename Ex>
exception_ptr make_exception_ptr (Ex ex)
 创建异常指针
exception_ptr MSTL_API current_exception ()
 获取当前异常
void MSTL_API rethrow_exception (const exception_ptr &p)
 重新抛出异常

变量

unique_ptr< exception_wrapperexception_ptr::ecb::wrapper
 异常包装器
atomic_int exception_ptr::ecb::ref_count {1}
 引用计数

详细描述

MSTL异常处理类与工具

宏定义说明

◆ MSTL_ERROR_BUILD_DERIVED_CLASS

#define MSTL_ERROR_BUILD_DERIVED_CLASS ( THIS,
BASE,
INFO )
值:
struct MSTL_API THIS : BASE { \
__MSTL_ERROR_CONSTRUCTOR(THIS, BASE, INFO) \
__MSTL_ERROR_DERIVED_DESTRUCTOR(THIS) \
__MSTL_ERROR_TYPE(THIS) \
};

构建可派生的异常类宏

参数
THIS当前类名
BASE基类名
INFO默认错误信息

快速定义可进一步派生的异常类。

在文件 exception.hpp44 行定义.

◆ MSTL_ERROR_BUILD_FINAL_CLASS

#define MSTL_ERROR_BUILD_FINAL_CLASS ( THIS,
BASE,
INFO )
值:
struct MSTL_API THIS final : BASE { \
__MSTL_ERROR_CONSTRUCTOR(THIS, BASE, INFO) \
__MSTL_ERROR_FINAL_DESTRUCTOR(THIS) \
__MSTL_ERROR_TYPE(THIS) \
};

构建最终异常类宏

参数
THIS当前类名
BASE基类名
INFO默认错误信息

快速定义不可派生的异常类。

在文件 exception.hpp60 行定义.

函数说明

◆ clone() [1/2]

virtual unique_ptr< exception_wrapper > exception_wrapper::clone ( ) const
pure virtual

克隆异常包装器

返回
异常包装器的唯一指针

创建当前异常包装器的深拷贝。

typed_exception_wrapper< Ex > 内被实现.

引用了 clone().

被这些函数引用 clone().

◆ clone() [2/2]

template<typename Ex>
MSTL_ALWAYS_INLINE unique_ptr< exception_wrapper > typed_exception_wrapper< Ex >::clone ( ) const
inlineoverridevirtual

克隆异常包装器

返回
异常包装器的唯一指针

实现了 exception_wrapper.

在文件 exception_ptr.hpp101 行定义.

引用了 _MSTL , 以及 make_unique().

◆ current_exception()

exception_ptr MSTL_API current_exception ( )
noexcept

获取当前异常

返回
当前异常的异常指针

捕获当前异常并创建异常指针。 如果当前没有异常被捕获,返回空的异常指针。

◆ ecb()

exception_ptr::ecb::ecb ( unique_ptr< exception_wrapper > wrapper)
inlineexplicit

构造函数

参数
wrapper异常包装器的唯一指针

在文件 exception_ptr.hpp129 行定义.

引用了 _MSTL, move() , 以及 wrapper.

◆ exception_ptr() [1/3]

exception_ptr::exception_ptr ( const exception_ptr & other)
inlinenoexcept

拷贝构造函数

参数
other要拷贝的异常指针

增加引用计数,共享异常对象。

在文件 exception_ptr.hpp186 行定义.

◆ exception_ptr() [2/3]

exception_ptr::exception_ptr ( exception_ptr && other)
inlinenoexcept

移动构造函数

参数
other要移动的异常指针

转移异常指针的所有权,不增加引用计数。

在文件 exception_ptr.hpp197 行定义.

◆ exception_ptr() [3/3]

exception_ptr::exception_ptr ( nullptr_t np = nullptr)
inlinenoexcept

默认构造函数

参数
np空指针字面量

创建一个空的异常指针,不引用任何异常。

在文件 exception_ptr.hpp178 行定义.

◆ exception_type()

MSTL_NODISCARD const std::type_info & exception_ptr::exception_type ( ) const
inlinenoexcept

获取异常类型信息

返回
异常的类型信息

如果异常指针为空,返回typeid(void)。

在文件 exception_ptr.hpp313 行定义.

◆ make_exception_ptr()

template<typename Ex>
exception_ptr make_exception_ptr ( Ex ex)
noexcept

创建异常指针

模板参数
Ex异常类型
参数
ex异常对象
返回
异常指针

创建引用指定异常的异常指针。 如果内存分配失败,返回空的异常指针。

在文件 exception_ptr.hpp332 行定义.

◆ operator bool()

exception_ptr::operator bool ( ) const
inlineexplicitnoexcept

布尔转换运算符

返回
是否持有异常

检查异常指针是否非空。

在文件 exception_ptr.hpp253 行定义.

◆ operator!=() [1/2]

bool exception_ptr::operator!= ( const exception_ptr & rhs) const
inlinenoexcept

不等比较运算符

参数
rhs右操作数
返回
是否不相等

在文件 exception_ptr.hpp273 行定义.

◆ operator!=() [2/2]

bool exception_ptr::operator!= ( nullptr_t ) const
inlinenoexcept

与空指针比较不等

返回
是否非空

在文件 exception_ptr.hpp296 行定义.

◆ operator=() [1/2]

exception_ptr & exception_ptr::operator= ( const exception_ptr & other)
inlinenoexcept

拷贝赋值运算符

参数
other要拷贝的异常指针
返回
当前异常指针的引用

在文件 exception_ptr.hpp218 行定义.

引用了 swap().

◆ operator=() [2/2]

exception_ptr & exception_ptr::operator= ( exception_ptr && other)
inlinenoexcept

移动赋值运算符

参数
other要移动的异常指针
返回
当前异常指针的引用

在文件 exception_ptr.hpp231 行定义.

引用了 _MSTL, move() , 以及 swap().

◆ operator==() [1/2]

bool exception_ptr::operator== ( const exception_ptr & rhs) const
inlinenoexcept

相等比较运算符

参数
rhs右操作数
返回
是否相等

比较两个异常指针是否引用同一个异常对象。

在文件 exception_ptr.hpp264 行定义.

◆ operator==() [2/2]

bool exception_ptr::operator== ( nullptr_t ) const
inlinenoexcept

与空指针比较相等

返回
是否为空

在文件 exception_ptr.hpp281 行定义.

◆ release()

MSTL_ALWAYS_INLINE void exception_ptr::ecb::release ( )
inlinenoexcept

减少引用计数

注解
当引用计数归零时,删除控制块

在文件 exception_ptr.hpp143 行定义.

引用了 memory_order_acq_rel, memory_order_acquire , 以及 ref_count.

被这些函数引用 exception_ptr::make_exception_ptr.

◆ rethrow() [1/2]

virtual void exception_wrapper::rethrow ( ) const
pure virtual

重新抛出异常

重新抛出被包装的异常。

typed_exception_wrapper< Ex > 内被实现.

◆ rethrow() [2/2]

template<typename Ex>
MSTL_ALWAYS_INLINE void typed_exception_wrapper< Ex >::rethrow ( ) const
inlineoverridevirtual

重新抛出异常

注解
重新抛出存储的异常

实现了 exception_wrapper.

在文件 exception_ptr.hpp85 行定义.

◆ rethrow_exception()

void MSTL_API rethrow_exception ( const exception_ptr & p)

重新抛出异常

参数
p异常指针

重新抛出异常指针引用的异常。

注解
如果异常指针为空,进程将被终止。

引用了 MSTL_END_NAMESPACE__ , 以及 rethrow_exception().

被这些函数引用 rethrow_exception().

◆ swap()

void exception_ptr::swap ( exception_ptr & other)
inlinenoexcept

交换两个异常指针

参数
other要交换的异常指针

在文件 exception_ptr.hpp243 行定义.

引用了 _MSTL , 以及 swap().

◆ throw_with_stack()

void MSTL_API throw_with_stack ( const exception & err)

抛出异常并打印堆栈信息

参数
err要抛出的异常对象

引用了 MSTL_END_NAMESPACE__ , 以及 throw_with_stack().

被这些函数引用 throw_with_stack().

◆ type() [1/2]

virtual const std::type_info & exception_wrapper::type ( ) const
pure virtualnoexcept

获取异常类型信息

返回
异常的类型信息

typed_exception_wrapper< Ex > 内被实现.

◆ type() [2/2]

template<typename Ex>
MSTL_ALWAYS_INLINE const std::type_info & typed_exception_wrapper< Ex >::type ( ) const
inlineoverridevirtualnoexcept

获取异常类型信息

返回
异常的类型信息

实现了 exception_wrapper.

在文件 exception_ptr.hpp93 行定义.

◆ typed_exception_wrapper() [1/2]

template<typename Ex>
typed_exception_wrapper< Ex >::typed_exception_wrapper ( const Ex & ex)
inline

拷贝构造函数

参数
ex要包装的异常

在文件 exception_ptr.hpp71 行定义.

◆ typed_exception_wrapper() [2/2]

template<typename Ex>
typed_exception_wrapper< Ex >::typed_exception_wrapper ( Ex && ex)
inlinenoexcept

移动构造函数

参数
ex要包装的异常

在文件 exception_ptr.hpp78 行定义.

引用了 _MSTL.

◆ ~exception_ptr()

exception_ptr::~exception_ptr ( )
inlinenoexcept

析构函数

减少引用计数,当引用计数为0时释放资源。

在文件 exception_ptr.hpp207 行定义.