Skip to content

Commit a1a6830

Browse files
authored
Add __cxa_current_exception_type for emscripten exceptions (#23739)
Fixes: #23734
1 parent 5ac14ef commit a1a6830

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

src/lib/libexceptions.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ var LibraryExceptions = {
179179
return info.excPtr;
180180
},
181181

182+
__cxa_current_exception_type() {
183+
if (!exceptionCaught.length) {
184+
return 0;
185+
}
186+
var info = exceptionCaught[exceptionCaught.length - 1];
187+
return info.get_type();
188+
},
189+
182190
__cxa_rethrow_primary_exception__deps: ['$ExceptionInfo', '$exceptionCaught', '__cxa_rethrow'],
183191
__cxa_rethrow_primary_exception: (ptr) => {
184192
if (!ptr) return;

src/lib/libsigs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ sigs = {
218218
__call_sighandler__sig: 'vpi',
219219
__cxa_begin_catch__sig: 'pp',
220220
__cxa_call_unexpected__sig: 'vp',
221+
__cxa_current_exception_type__sig: 'p',
221222
__cxa_current_primary_exception__sig: 'p',
222223
__cxa_end_catch__sig: 'v',
223224
__cxa_rethrow__sig: 'v',

test/test_other.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9579,6 +9579,23 @@ def test_exceptions_rethrow_stack_trace_and_message(self):
95799579
expected_output=rethrow_stack_trace_checks, regex=True)
95809580
self.assertNotContained('important_function', err)
95819581

9582+
@with_all_eh_sjlj
9583+
def test_cxa_current_exception_type(self):
9584+
create_file('main.cpp', r'''
9585+
#include <cstdio>
9586+
#include <stdexcept>
9587+
#include <typeinfo>
9588+
#include <cxxabi.h>
9589+
9590+
int main() {
9591+
try {
9592+
throw std::runtime_error("ERROR");
9593+
} catch (...) {
9594+
printf("__cxa_current_exception_type: %s\n", abi::__cxa_current_exception_type()->name());
9595+
}
9596+
}''')
9597+
self.do_runf('main.cpp', '__cxa_current_exception_type: St13runtime_error')
9598+
95829599
@with_all_eh_sjlj
95839600
def test_exceptions_exit_runtime(self):
95849601
self.set_setting('EXIT_RUNTIME')

0 commit comments

Comments
 (0)