--- John Gunnarsson wrote:
> As you can see the cleanup code is duplicated 3 times (not very DRY)
> If I would have implemented the same scenario in c# the cleanupcode
> would have been placed in a "finally" clause only once, and would be
> executed wither an exception occured or not.
> 
> Since I'm quite new to c++ I'm sure I just missed something very
> vital here, and would like to know how you solve scenarios 
> like this in C++.

Generally it is not a good practice to have stuff like:

try
{
    ...* x= new Something;
    ...
    delete x;
}
catch()
{
}

The solution is to create objects on the stack, or use some kind of
wrapper object (a proxy, smart pointer, whatever) and have it's
constructor allocate the memory and have it's destructor free that memory.


-- 

Milan Babuskov
http://www.guacosoft.com


Reply via email to