Re: try, finally

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Mar 19, 2008 at 12:13 PM, Jason Cipriani
<jason.cipriani@xxxxxxxxx> 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?

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux