The following example leave a possible memory leak because the destructor doesn't run for the object on which the exception is handled during its constructor is run. where do i handle this memory leak?
#include <exception>
class MyClass {
public:
MyClass()
{
c = new char[5];
throw std::runtime_error("test");
}
~MyClass ()
{
delete[] c;
}
private:
char *c;
};
int main()
{
try
{
MyClass Obj;
}
catch (std::runtime_error)
{
}
}