I have a class:
class Foo
{
public:
Foo()
{
something_ = new int;
throw std::exception("Bad");
}
~Foo()
{
delete something_;
}
}
Then I have this sample code:
// Destructor is called
{
std::unique_ptr<Foo> foo;
foo.reset(new Foo());
}
// Destructor is NOT called
try
{
std::unique_ptr<Foo> foo;
foo.reset(new Foo());
}
catch(std::exception e)
{
}
I'm not quite clear on why the destructor isn't called in the try/catch. Does the unique_ptr scope not expire for it to call the dtor?
Thanks for any information.