T
Tony Johansson
Hello Experts!
Assume foo is a method in a some class or a stand-alone function and method
push is throwing an exception of class logic_error.
Assume also that I want to handle this exception in foo if it's possible.
This will cause a problem because C++ doesn't have the finally keyword and I
can't do delete both in the exception handler and after the exception
handler that's because I have put in the throw to throw it further
to let some other method to handle it. But if I remove this throw how is it
then possible to get a
solution that will hold and i a good solution. If I just remove this throw
and an exception occurs will this cause delete s two times and resuting in
undefined behaviour.
void foo()
{
IntStack* s
try
{
s = new IntStack(20);
s->push(20);
}
catch(const logic_error& e)
{
delete s;
throw; //
}
delete s;
}
Many thanks
//Tony
Assume foo is a method in a some class or a stand-alone function and method
push is throwing an exception of class logic_error.
Assume also that I want to handle this exception in foo if it's possible.
This will cause a problem because C++ doesn't have the finally keyword and I
can't do delete both in the exception handler and after the exception
handler that's because I have put in the throw to throw it further
to let some other method to handle it. But if I remove this throw how is it
then possible to get a
solution that will hold and i a good solution. If I just remove this throw
and an exception occurs will this cause delete s two times and resuting in
undefined behaviour.
void foo()
{
IntStack* s
try
{
s = new IntStack(20);
s->push(20);
}
catch(const logic_error& e)
{
delete s;
throw; //
}
delete s;
}
Many thanks
//Tony