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: (lack of) Thread-safe exceptions on AIX (gcc-2.95.1)


The Microsoft exception handling in C syntax is described at: (SEH)
http://msdn.microsoft.com/library/devprods/vs6/visualc/vccore/_core_exception_handling_topics_.28.seh.29.htm

The relavent keywords are: __try, __except, and __finally.

Example __try/__except code:

__try {
    float x, y=0;
    x = 5 / y;        // This exception handled by outer block
    __try {
        x = 0;
        y = 27 / x;   // This exception handled by inner block
    }
    __except( GetExceptionCode() == STATUS_FLOATING_DIVIDE_BY_ZERO) {
        printf("handled by inner block");
    }
}
__except( GetExceptionCode() == STATUS_FLOATING_DIVIDE_BY_ZERO ) {
    printf( "handled by outer block" );
}

The return value of the __except filter is treated specially.
If it returns 1, the except block is executed.
If it returns 0, the exception handler search continues.
If it returns -1, the exception is dismissed and execution continues
at the point the exception originally occurred.

GetExceptionCode() is required to appear in the filter expression, any
function called in the filter can't call GetExceptionCode() and expect
to get the correct value.

If you want to raise a specfic SEH exception manually, you use the
RaiseException() function.

A __try/__finally handler works as one would expect.

example code:

void *pv = NULL;

__try
{
  pv = malloc(1);
  .....
}
__finally
{
  if (pv) free(pv);
}

The AbnormalTermination returns TRUE in the __finally block if indeed
the block was executed due to an exception being thrown, otherwise it
returns FALSE.

Other wierd details:
You can't use a goto to jump into a __try or __finally block.  You
can't nest __try/__except or __try/__finally handlers inside a
__finally block.

The only other relavent detail being that you should observe caution
when using goto, or return to exit a __finally block.

SEH are asynchronous exceptions, so they adversly effect the
optimization opportunities, use them with care.

For information on how SEH and C++ exceptions interact check out the
MSDN docs on the subject:

http://msdn.microsoft.com/library/devprods/vs6/visualc/vccore/_core_exception_handling_differences.htm

For the gorey details of how SEH actually gets implemented check out:
http://msdn.microsoft.com/library/periodic/period97/pietrek.htm

Hope this explains things,
Bill



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