C++ Exception 库 - Constructor
描述
这是构造函数异常。
声明
以下是 std::exception::exception 的声明。
exception() throw(); exception (const exception& e) throw();
C++11
exception() noexcept; exception (const exception& e) noexcept;
参数
e − 它是另一个异常对象。
返回值
none
异常
No-throw guarantee − 没有成员抛出异常。
示例
在下面的 std::exception::exception 示例中。
#include <iostream>
#include <exception>
struct ooops : std::exception {
const char* what() const noexcept {return "Exception test!\n";}
};
int main () {
ooops e;
std::exception* p = &e;
try {
throw e;
} catch (std::exception& ex) {
std::cout << ex.what();
}
try {
throw *p;
} catch (std::exception& ex) {
std::cout << ex.what();
}
return 0;
}
示例输出应该是这样的 −
Exception test! std::exception

