#include<iostream>
using namespace std;
class test
{
public:
test()
{
cout<<"hello";}
~test()
{
cout<<"hi";
throw "const";
}
void display()
{
cout<<"faq";
}
};
int main()
{
test t;
try{
}
catch(char const *e)
{
cout<<e;
}
t.display();
}
output:
i know by throwing exception from destructor i’m violating basic c++ laws but still i want to know is their any way the exception can be handled.
Your destructor runs outside the
try–catchblock –t‘s scope is themainfunction. but then raising exceptions from a destructor is a Bad IdeaTM.