#include <exception>
#include <iostream>
template <typename T>
class smart_ptr
{
public:
smart_ptr(T* p) : m_p(p)
{
std::cout << "ctor smart_ptr" <<std::endl;
}
~smart_ptr()
{
std::cout <<"dtor smart_ptr" << std::endl;
delete m_p;
}
private:
T* m_p;
};
class Widget
{
public:
Widget()
{
//comment the following line out to see what happens
//throw std::runtime_error("bad things happen");
}
};
int main()
{
try
{
smart_ptr<Widget> pWidget(new Widget());
}
catch( std::exception&)
{
}
return 0;
}