uncaught_exception

仅当引发的异常当前进程,返回 true。

bool uncaught_exception( );

返回值

由于引发表达式,在完成引发表达式的求值返回之后 true 并在完成异常声明的初始化匹配的处理程序或调用 意外 之前。 具体而言,uncaught_exception 将返回 true,在调用从异常时调用堆栈展开的析构函数。 在计算机上,uncaught_exception 在Windows CE 5.00和更高版本只支持,包括Windows Mobile 2005平台。

示例

// exception_uncaught_exception.cpp
// compile with: /EHsc
#include <exception>
#include <iostream>
#include <string>

class Test 
{
public:
   Test( std::string msg ) : m_msg( msg ) 
   {
      std::cout << "In Test::Test(\"" << m_msg << "\")" << std::endl;
   }
   ~Test( ) 
   {
      std::cout << "In Test::~Test(\"" << m_msg << "\")" << std::endl
         << "        std::uncaught_exception( ) = "
         << std::uncaught_exception( )
         << std::endl;
   }
private:
    std::string m_msg;
};

// uncaught_exception will be true in the destructor 
// for the object created inside the try block because 
// the destructor is being called as part of the unwind.

int main( void )
   {
      Test t1( "outside try block" );
      try 
      {
         Test t2( "inside try block" );
         throw 1;
      }
      catch (...) {
   }
}
  

要求

标题: <exception>

命名空间: std