Why does the __cxa_rethrow always increment uncaughtExceptions?
盏一
w@hidva.com
Fri May 26 07:56:10 GMT 2023
For native exceptions, it is reasonable to increment uncaughtExceptions in __cxa_rethrow because __cxa_begin_catch performs the corresponding decrement operation. However, for foreign exceptions, __cxa_begin_catch does not perform the decrement operation on uncaughtExceptions, and in fact, no function will decrement uncaughtExceptions at this point. This causes uncaughtExceptions to be incremented every time a foreign exception is rethrown, as shown in https://godbolt.org/z/G6fKrjEvM.
On the contrary, clang libc++ only increments uncaughtExceptions for native exceptions:
```
void __cxa_rethrow() {
__cxa_eh_globals* globals = __cxa_get_globals();
__cxa_exception* exception_header = globals->caughtExceptions;
if (NULL == exception_header)
std::terminate(); // throw; called outside of a exception handler
bool native_exception = __isOurExceptionClass(&exception_header->unwindHeader);
if (native_exception)
{
exception_header->handlerCount = -exception_header->handlerCount;
globals->uncaughtExceptions += 1;
}
else // this is a foreign exception
{
globals->caughtExceptions = 0;
}
}
```
Best regards,
盏一
More information about the Libstdc++
mailing list