We consider that an exception in initialization may happen. So we write try / catch block.
int f(){
throw 1;
}
class A
{
public:
A() try : _k(f())
{}
catch (int)
{
std::cout << "Exception 1" << std::endl;
}
private:
int _k;
};
But the catch rethrows exception on one level deeper. Thats means that next code
try
{
A a;
} catch(int)
{
std::cout << "Exception 2" << std::endl;
}
will output:
Exception 1
Exception 2
Why this try / catch block behaves not the same way as ordinary try / catch block?
Full code example: http://ideone.com/XjY2d
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With