@@ -265,6 +265,7 @@ void __cxa_end_catch() {
265
265
__cxa_exception *current_exception = globals->caughtExceptions ;
266
266
267
267
if (NULL != current_exception) {
268
+ // TODO: Handle foreign exceptions? How?
268
269
if (current_exception->handlerCount < 0 ) {
269
270
// The exception has been rethrown
270
271
if (0 == incrementHandlerCount (current_exception)) {
@@ -319,19 +320,22 @@ std::type_info * __cxa_current_exception_type() {
319
320
(in an implementation-defined way) as being rethrown.
320
321
* If the caughtExceptions stack is empty, it calls terminate()
321
322
(see [C++FDIS] [except.throw], 15.1.8).
322
- * It then returns to the handler that called it, which must call
323
- __cxa_end_catch(), perform any necessary cleanup, and finally
324
- call _Unwind_Resume() to continue unwinding.
323
+ * It then calls _Unwind_Resume_or_Rethrow which should not return
324
+ (terminate if it does).
325
325
*/
326
326
extern LIBCXXABI_NORETURN void __cxa_rethrow () {
327
327
__cxa_eh_globals *globals = __cxa_get_globals ();
328
- __cxa_exception *exception = exception_from_exception_object ( globals->caughtExceptions ) ;
328
+ __cxa_exception *exception = globals->caughtExceptions ;
329
329
330
330
if (NULL == exception ) // there's no current exception!
331
331
std::terminate ();
332
332
333
- // Mark the exception as being rethrown
334
- exception ->handlerCount = -exception ->handlerCount ; // TODO: Atomic
333
+ // TODO: Handle foreign exceptions? How?
334
+
335
+ // Mark the exception as being rethrown (reverse the effects of __cxa_begin_catch)
336
+ exception ->handlerCount = -exception ->handlerCount ;
337
+ globals->uncaughtExceptions += 1 ;
338
+ // __cxa_end_catch will remove this exception from the caughtExceptions stack if necessary
335
339
336
340
#if __arm__
337
341
(void ) _Unwind_SjLj_Resume_or_Rethrow (&exception ->unwindHeader );
0 commit comments