set_unexpected (<exception>)

建立新 unexpected_handler 是意外的异常遇到。

unexpected_handler
   set_unexpected(
      unexpected_handler _Pnew
   ) throw( );

参数

  • _Pnew
    将调用的函数。

返回值

前面的 unexpected_handler的地址。

备注

_Pnew 不能为 null 指针。

C++标准要求 unexpected 调用,当函数引发不在其引发列表的异常时。 当前实现不支持此操作。 下面的示例直接调用 unexpected,然后调用 unexpected_handler

示例

// exception_set_unexpected.cpp
// compile with: /c /EHsc
#include<exception>
#include<iostream>

using namespace std;

void unfunction( ) 
{
   cout << "I'll be back." << endl;
   terminate( );
}

int main( ) 
{
   unexpected_handler oldHand = set_unexpected( unfunction );
   unexpected( );
}
  
  
  

要求

标题: <exception>

命名空间: std