C++ Exception Library - bad_exception



Description

This an exception thrown by unexpected handler.

Declaration

Following is the declaration for std::bad_exception.

class bad_exception;

C++11

class bad_exception;

Parameters

none

Return Value

none

Exceptions

No-throw guarantee − no members throw exceptions.

Example

In below example for 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';
   }
}

The sample output should be like this −

Caught std::bad_exception
exception.htm
Advertisements