This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: EH in C (was: Re: (lack of) Thread-safe exceptions on AIX(gcc-2.95.1)




On Mon, 31 Jan 2000, Bill Tutt wrote:

> > David Starner wrote:
> > Interesting. Wouldn't it be better just to add C++ exception handling,
> though?
> > It's substantially the same, but C++ EH is more general and has clear
> effects
> > with C++ EH over current implementations.
> 
> Um.. C++ exception handling semantics depend on classes/structs being
> able to have destructors. Thus MS's creation of __finally.  The
> difference between picking __catch vs. __except I would imagine was
> done so it was visually different from the C++ spelling as to try and
> reduce confusion as much as possible.

This is what catch(...) { throw;} is for. It works just like finally.

#include<stdio.h>
#include<stdexcept>
  using std::runtime_error;

void foo()
  {
    throw runtime_error("Barf!");
  }

void bar()
  {
    FILE* fp=fopen("foo","w");

    try
    {
      foo();
    }
    catch(...)
    {
      fclose(fp);
      printf("File closed.\n");
      throw;
    }
  }

int main()
  {
    try
    {
      bar();
    }
    catch(...)
    {
    }

    return(0);
  }


[snip]


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]