Skip to content

Commit b7dcaab

Browse files
authored
[EH] Increment uncaughtExceptionCount in __cxa_rethrow_primary_exception (#26527)
This was missing, causing `std::uncaught_exceptions()` to return incorrect values.
1 parent d246366 commit b7dcaab

6 files changed

Lines changed: 38 additions & 2 deletions

src/lib/libexceptions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ var LibraryExceptions = {
226226
var info = new ExceptionInfo(ptr);
227227
info.set_rethrown(true);
228228
info.set_caught(false);
229+
uncaughtExceptionCount++;
229230
#if !DISABLE_EXCEPTION_CATCHING
230231
___cxa_increment_exception_refcount(ptr);
231232
exceptionLast = new CppException(ptr);
File renamed without changes.
File renamed without changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <stdexcept>
2+
#include <stdio.h>
3+
4+
struct DestructorTester {
5+
~DestructorTester() {
6+
printf("Destructor Uncaught: %d\n", std::uncaught_exceptions());
7+
}
8+
};
9+
10+
int main() {
11+
std::exception_ptr p;
12+
try {
13+
throw std::runtime_error("test");
14+
} catch (...) {
15+
p = std::current_exception();
16+
}
17+
18+
printf("Before Uncaught: %d\n", std::uncaught_exceptions());
19+
try {
20+
DestructorTester dt;
21+
std::rethrow_exception(p);
22+
} catch (...) {
23+
printf("In catch Uncaught: %d\n", std::uncaught_exceptions());
24+
}
25+
printf("After Uncaught: %d\n", std::uncaught_exceptions());
26+
return 0;
27+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Before Uncaught: 0
2+
Destructor Uncaught: 1
3+
In catch Uncaught: 0
4+
After Uncaught: 0

test/test_core.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,8 +1457,12 @@ def test_exceptions_rethrow(self):
14571457
self.do_core_test('test_exceptions_rethrow.cpp')
14581458

14591459
@with_all_eh_sjlj
1460-
def test_exceptions_uncaught_count(self):
1461-
self.do_core_test('test_exceptions_uncaught_count.cpp')
1460+
def test_exceptions_uncaught_3(self):
1461+
self.do_core_test('test_exceptions_uncaught_3.cpp')
1462+
1463+
@with_all_eh_sjlj
1464+
def test_exceptions_uncaught_4(self):
1465+
self.do_core_test('test_exceptions_uncaught_4.cpp')
14621466

14631467
@with_all_eh_sjlj
14641468
def test_exceptions_resume(self):

0 commit comments

Comments
 (0)