C++ 異常庫 - bad_exception



描述

這是一個由意外處理程式丟擲的異常。

宣告

以下是 std::bad_exception 的宣告。

class bad_exception;

C++11

class bad_exception;

引數

返回值

異常

無丟擲保證 - 沒有成員丟擲異常。

示例

以下為 std::bad_exception 的示例。

#include <iostream>
#include <exception>
#include <stdexcept>
 
void my_unexp() { throw; }
 
void test() throw(std::bad_exception) {
   throw std::runtime_error("test error");
}
 
int main() {
   std::set_unexpected(my_unexp);
   try {
      test();
   } catch(const std::bad_exception& e) {
      std::cerr << "Caught " << e.what() << '\n';
   }
}

示例輸出應如下所示:

Caught std::bad_exception
exception.htm
廣告

© . All rights reserved.