次の方法で共有


uncaught_exception

スローされた例外が現在処理されている場合にのみ true を返します。

bool uncaught_exception( );

戻り値

throw 式のと一致するハンドラーの例外宣言の初期化を完了するか、throw 式の結果として 予期しない を呼び出す前の評価が完了した後 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 (...) {
   }
}
  

必要条件

ヘッダー: <例外>

名前空間: std