目录

(constructor)

描述 (Description)

它是构造函数异常。

声明 (Declaration)

以下是std :: exception :: exception的声明。

	
exception() throw();
exception (const exception& e) throw();

C++11

	
exception() noexcept;
exception (const exception& e) noexcept;

参数 (Parameters)

e - 这是另一个异常对象。

返回值 (Return Value)

没有

异常 (Exceptions)

No-throw guarantee - 没有成员抛出异常。

例子 (Example)

在下面的示例中为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 
↑回到顶部↑
WIKI教程 @2018