其实是可以的,早在C++11中就引入了这么一个强大的机制,即std::nested_exception.,正确的使用可以使我们在C++中实现printStackTrace,可以帮助我们更好的排查错误.这是这个类现在看来唯一的用处,但是却是一个十分强大的武器.
C++中异常处理机制是C++相比与C的主要特征之一,其中一点有点令人沮丧,就是无法像java那样直接使用printStackTrace来进行栈追踪,其实是可以的,早在C++11中就引入了这么一个强大的机制,即std::nested_exception.,正确的使用可以使我们在C++中实现printStackTrace,可以帮助我们更好的排查错误.这是这个类现在看来唯一的用处...
std::nested_exception From cppreference.com <cpp |error Defined in header<exception> classnested_exception; (since C++11) std::nested_exceptionis a polymorphic mixin class which can capture and store the current exception, making it possible to nest exceptions of arbitrary types within each ...
class nested_exception; (C++11 起) std::nested_exception 是一个多态混入类,可以捕获并存储当前异常,令任意类型的异常彼此间内嵌可行。 成员函数(构造函数) 构造nested_exception (公开成员函数) (析构函数) [虚] 析构nested exception (虚公开成员函数) operator= 替换nested_exception 的内容 (公开成...
nested_exception::nested_ptr [[noreturn]]voidrethrow_nested()const; (since C++11) Rethrows the stored exception. If there is no stored exceptions (i.e.nested_ptr()returns null pointer), thenstd::terminateis called. Parameters (none)
nested_exception::operator= nested_exception::rethrow_nested nested_exception::nested_ptr Constructs newnested_exceptionobject. 1)Default constructor. Stores an exception object obtained by callingstd::current_exception()within the newnested_exceptionobject. ...
std::nested_exception Member functions nested_exception::nested_exception nested_exception::~nested_exception nested_exception::operator= nested_exception::rethrow_nested nested_exception::nested_ptr virtual ~nested_exception() = default; (since C++11) Destroys the nested exception object. Retrieved ...