* Why does the __cxa_rethrow always increment uncaughtExceptions?
@ 2023-05-26 7:56 盏一
0 siblings, 0 replies; 2+ messages in thread
From: 盏一 @ 2023-05-26 7:56 UTC (permalink / raw)
To: libstdc++
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,
盏一
^ permalink raw reply [flat|nested] 2+ messages in thread
* Why does the __cxa_rethrow always increment uncaughtExceptions?
@ 2023-05-26 8:09 盏一
0 siblings, 0 replies; 2+ messages in thread
From: 盏一 @ 2023-05-26 8:09 UTC (permalink / raw)
To: libstdc++
(Sorry, this email is to fix the broken link and format in the previous email.
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
I also wanted to note that clang libc++ only increments uncaughtExceptions for native exceptions,
as shown in the code snippet below:
```
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,
盏一
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-05-26 8:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-26 7:56 Why does the __cxa_rethrow always increment uncaughtExceptions? 盏一
2023-05-26 8:09 盏一
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).