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