I have written following program
#include <iostream>
#include <stdexcept>
class Myclass
{
public:
~Myclass()
{
//throw std::runtime_error("second (in destructor)");
throw 1;
}
};
void fun()
{
Myclass obj;
}
int main()
{
try
{
fun();
}
catch (const std::exception& e)
{
std::cout << e.what();
}
catch(...)
{
std::cout << " ... default Catch" << std::endl;
}
std::cout << "Normal" << std::endl;
return 0;
}
When I run above program in C++98
mode (cpp.sh) it prints
... default Catch
Normal
When I run it with C++14
mode, it does not print anything. Why is there a change in this behavior?
I do understand that whenever any exception occurred and any destructor
(within stack unwinding process) throws any exception, it terminates the application. But here only one time exception is thrown from try
block that is from destructor
.