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

Bill Tutt rassilon@list.org
Tue Feb 1 00:22:00 GMT 2000


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

No it doesn't.
__finally() always gets executed. The catch(...) block is only executed 
when an exception is thrown.

In this example, the fprintf() always occurs. In your example if foo()
hadn't thrown the exception, the fclose() would never have gotten called.

__try
{
  .....
}
__finally
{
  fprintf("I'm inside of __finally.\n");
}

__finally's sole purpose in life is to give C code (not C++, C) the chance
to perform cleanup actions in the face of asynchrnous exceptions (divide
by zero, AV, etc), SEH generated synchronous exceptions, and C++ generated
synchrnous exceptions. SEH wouldn't need __finally if C supported
destructors, but C doesn't, and I don't think it should. 

Bill




More information about the Gcc mailing list