From 0d356829b435cfa682c1514676f290441225606e Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Sat, 21 Mar 2026 09:41:03 +0000 Subject: [PATCH 1/3] Increment uncaughtExceptionCount in __cxa_rethrow_primary_exception This was missing, causing `std::uncaught_exceptions()` to return incorrect values. --- src/lib/libexceptions.js | 1 + ...st_exceptions_rethrow_primary_uncaught.cpp | 28 +++++++++++++++++++ ...st_exceptions_rethrow_primary_uncaught.out | 4 +++ test/test_core.py | 4 +++ 4 files changed, 37 insertions(+) create mode 100644 test/core/test_exceptions_rethrow_primary_uncaught.cpp create mode 100644 test/core/test_exceptions_rethrow_primary_uncaught.out diff --git a/src/lib/libexceptions.js b/src/lib/libexceptions.js index c3a05a763e819..43e8ea161368f 100644 --- a/src/lib/libexceptions.js +++ b/src/lib/libexceptions.js @@ -226,6 +226,7 @@ var LibraryExceptions = { var info = new ExceptionInfo(ptr); info.set_rethrown(true); info.set_caught(false); + uncaughtExceptionCount++; #if !DISABLE_EXCEPTION_CATCHING ___cxa_increment_exception_refcount(ptr); exceptionLast = new CppException(ptr); diff --git a/test/core/test_exceptions_rethrow_primary_uncaught.cpp b/test/core/test_exceptions_rethrow_primary_uncaught.cpp new file mode 100644 index 0000000000000..b05627f793c27 --- /dev/null +++ b/test/core/test_exceptions_rethrow_primary_uncaught.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +struct DestructorTester { + ~DestructorTester() { + std::cout << "Destructor Uncaught: " << std::uncaught_exceptions() << "\n"; + } +}; + +int main() { + std::exception_ptr p; + try { + throw std::runtime_error("test"); + } catch (...) { + p = std::current_exception(); + } + + std::cout << "Before Uncaught: " << std::uncaught_exceptions() << "\n"; + try { + DestructorTester dt; + std::rethrow_exception(p); + } catch (...) { + std::cout << "In catch Uncaught: " << std::uncaught_exceptions() << "\n"; + } + std::cout << "After Uncaught: " << std::uncaught_exceptions() << "\n"; + return 0; +} diff --git a/test/core/test_exceptions_rethrow_primary_uncaught.out b/test/core/test_exceptions_rethrow_primary_uncaught.out new file mode 100644 index 0000000000000..ff68d1b2a2815 --- /dev/null +++ b/test/core/test_exceptions_rethrow_primary_uncaught.out @@ -0,0 +1,4 @@ +Before Uncaught: 0 +Destructor Uncaught: 1 +In catch Uncaught: 0 +After Uncaught: 0 diff --git a/test/test_core.py b/test/test_core.py index dfdbdb1eba9ed..a2c2f1a2a5773 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -1456,6 +1456,10 @@ def test_exceptions_alias(self): def test_exceptions_rethrow(self): self.do_core_test('test_exceptions_rethrow.cpp') + @with_all_eh_sjlj + def test_exceptions_rethrow_primary_uncaught(self): + self.do_core_test('test_exceptions_rethrow_primary_uncaught.cpp') + @with_all_eh_sjlj def test_exceptions_uncaught_count(self): self.do_core_test('test_exceptions_uncaught_count.cpp') From ab28470a551753bad15e09870f5918c67e69ec95 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Tue, 24 Mar 2026 15:30:10 +0000 Subject: [PATCH 2/3] std::cout -> printf --- .../core/test_exceptions_rethrow_primary_uncaught.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/core/test_exceptions_rethrow_primary_uncaught.cpp b/test/core/test_exceptions_rethrow_primary_uncaught.cpp index b05627f793c27..b59859936fdcd 100644 --- a/test/core/test_exceptions_rethrow_primary_uncaught.cpp +++ b/test/core/test_exceptions_rethrow_primary_uncaught.cpp @@ -1,10 +1,9 @@ -#include -#include #include +#include struct DestructorTester { ~DestructorTester() { - std::cout << "Destructor Uncaught: " << std::uncaught_exceptions() << "\n"; + printf("Destructor Uncaught: %d\n", std::uncaught_exceptions()); } }; @@ -16,13 +15,13 @@ int main() { p = std::current_exception(); } - std::cout << "Before Uncaught: " << std::uncaught_exceptions() << "\n"; + printf("Before Uncaught: %d\n", std::uncaught_exceptions()); try { DestructorTester dt; std::rethrow_exception(p); } catch (...) { - std::cout << "In catch Uncaught: " << std::uncaught_exceptions() << "\n"; + printf("In catch Uncaught: %d\n", std::uncaught_exceptions()); } - std::cout << "After Uncaught: " << std::uncaught_exceptions() << "\n"; + printf("After Uncaught: %d\n", std::uncaught_exceptions()); return 0; } From d7fffa4fc361802ff8c4e394605fc1b0847fadf2 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Tue, 24 Mar 2026 16:15:07 +0000 Subject: [PATCH 3/3] Rename uncaught tests --- ..._uncaught_count.cpp => test_exceptions_uncaught_3.cpp} | 0 ..._uncaught_count.out => test_exceptions_uncaught_3.out} | 0 ...rimary_uncaught.cpp => test_exceptions_uncaught_4.cpp} | 0 ...rimary_uncaught.out => test_exceptions_uncaught_4.out} | 0 test/test_core.py | 8 ++++---- 5 files changed, 4 insertions(+), 4 deletions(-) rename test/core/{test_exceptions_uncaught_count.cpp => test_exceptions_uncaught_3.cpp} (100%) rename test/core/{test_exceptions_uncaught_count.out => test_exceptions_uncaught_3.out} (100%) rename test/core/{test_exceptions_rethrow_primary_uncaught.cpp => test_exceptions_uncaught_4.cpp} (100%) rename test/core/{test_exceptions_rethrow_primary_uncaught.out => test_exceptions_uncaught_4.out} (100%) diff --git a/test/core/test_exceptions_uncaught_count.cpp b/test/core/test_exceptions_uncaught_3.cpp similarity index 100% rename from test/core/test_exceptions_uncaught_count.cpp rename to test/core/test_exceptions_uncaught_3.cpp diff --git a/test/core/test_exceptions_uncaught_count.out b/test/core/test_exceptions_uncaught_3.out similarity index 100% rename from test/core/test_exceptions_uncaught_count.out rename to test/core/test_exceptions_uncaught_3.out diff --git a/test/core/test_exceptions_rethrow_primary_uncaught.cpp b/test/core/test_exceptions_uncaught_4.cpp similarity index 100% rename from test/core/test_exceptions_rethrow_primary_uncaught.cpp rename to test/core/test_exceptions_uncaught_4.cpp diff --git a/test/core/test_exceptions_rethrow_primary_uncaught.out b/test/core/test_exceptions_uncaught_4.out similarity index 100% rename from test/core/test_exceptions_rethrow_primary_uncaught.out rename to test/core/test_exceptions_uncaught_4.out diff --git a/test/test_core.py b/test/test_core.py index a2c2f1a2a5773..5bb1d1bd349a3 100644 --- a/test/test_core.py +++ b/test/test_core.py @@ -1457,12 +1457,12 @@ def test_exceptions_rethrow(self): self.do_core_test('test_exceptions_rethrow.cpp') @with_all_eh_sjlj - def test_exceptions_rethrow_primary_uncaught(self): - self.do_core_test('test_exceptions_rethrow_primary_uncaught.cpp') + def test_exceptions_uncaught_3(self): + self.do_core_test('test_exceptions_uncaught_3.cpp') @with_all_eh_sjlj - def test_exceptions_uncaught_count(self): - self.do_core_test('test_exceptions_uncaught_count.cpp') + def test_exceptions_uncaught_4(self): + self.do_core_test('test_exceptions_uncaught_4.cpp') @with_all_eh_sjlj def test_exceptions_resume(self):