This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: try, finally
On Wed, Mar 19, 2008 at 12:13 PM, Jason Cipriani
<jason.cipriani@gmail.com> wrote:
> Does GCC have anything similar to the MS and Borland compiler's __try
> and __finally keywords? When using GCC I often find that I have code
> like this (a moderately complex, and highly contrived, example):
>
> ====
>
> [snip code]
>
Basically the same thing in C++:
If you wanted it as an array:
#include <vector>
std::vector<char> data1(1000), data2(1000), data3(1000);
Or, if you're allocating for an object,
#include <memory>
std::auto_ptr<whatever> data1(new whatever);
std::auto_ptr<whatever> data2(new whatever);
std::auto_ptr<whatever> data3(new whatever);
And that's it. C++'s (default) new throws on failure instead of
returning 0, and the destructors make sure everything that's been
constructed gets destructed properly.
Why bother with void* and C?