Hmmm, canīt really grasp the logic of std::bad_exception or I am simple using it wrong. Iīve tried to make a board seach on the topic but I wasnīt succesful. If I understand it correctly std::bad_exception is used when an exception is thrown that isnīt declared in the exception specification, e.i.
Code:
#include <iostream>
#include <conio.h>
#include <exception>
using namespace std;
class A
{};
class B
{};
void test() throw(A, std::bad_exception)
{
throw B();//Here should it throw a std::bad_exception type
//throw A(); //This works okey
}
int main(void)
{
try
{
test();
}
catch(A)
{
cout << "Error in CLASS A" << endl;
}
//Canīt catch it here
catch(std::bad_exception)
{
cout << "Error in std::bad_exception" << endl;
}
getch();
return 0;
}
When I run this code I get a "abnormal program termination". When I delved deeper in my book I found that that the line
Code:
throw B();//Here should it throw a std::bad_exception type
actually doesnīt throw it directly but it goes through a function called unexpected() which calls another function, terminate(), that terminates the program (like in my case). Well if it terminates the program and you have no acces to the "supposed" thrown object, then whats the purpose of std::bad_exception??? Iīm totaly lost.