Yes. Throw an exception from the destructor caused by the stack refusing to handle another exception:
struct D
{
~D()
{
std::cout << std::uncaught_exceptions() << std::endl;
}
};
struct E
{
~E()
{
try
{
D d_;
throw 2;
}
catch(...)
{
std::cout << std::uncaught_exceptions() << std::endl;
}
}
};
int main()
{
try
{
D d;
E e;
throw 1;
}
catch(...)
{
}
}
dThe destructor will be called, and 1is still an active exception. So std::uncaught_exceptions()inside ~dwill be equal to 1.
e , 1 . . a d, . 1, 2 , std::uncaught_exceptions() ~d_ 2.
std::uncaught_exceptions , . , - . , . RAII, , - .