Skip to content

Commit 22e3b04

Browse files
authored
[EH] Simplify exception format message (#17003)
This makes exception format message format the same as that of `demangling_terminate_handler`, which is called when an uncaught exception terminates the program: https://github.com/emscripten-core/emscripten/blob/d5ef6937fe395488e23a82c1e582a7ea5c2dab83/system/lib/libcxxabi/src/cxa_default_handlers.cpp#L62-L72 This removes 'address' from the message when an exception does not inherit from `std::exception`, but I guess it's fine; we didn't print the address in case of `std::exception` anyway.
1 parent e5d6d6b commit 22e3b04

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

system/lib/libcxxabi/src/format_exception.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ char* emscripten_format_exception(void* thrown_object) {
3434
if (can_catch) {
3535
const char* what =
3636
static_cast<const std::exception*>(thrown_object)->what();
37-
asprintf(&result, "Cpp Exception %s: %s", type_name, what);
38-
} else {
3937
asprintf(&result,
40-
"Cpp Exception: The exception is an object of type '%s' at "
41-
"address %p which does not inherit from std::exception",
38+
"terminating with uncaught exception of type %s: %s",
4239
type_name,
43-
thrown_object);
40+
what);
41+
} else {
42+
asprintf(
43+
&result, "terminating with uncaught exception of type %s", type_name);
4444
}
4545

4646
if (demangled_buf) {

tests/test_core.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,11 +1660,11 @@ class myexception : public exception {
16601660
}
16611661
'''
16621662
expected = '''\
1663-
Cpp Exception: The exception is an object of type 'int' at address xxx which does not inherit from std::exception
1664-
Cpp Exception: The exception is an object of type 'char' at address xxx which does not inherit from std::exception
1665-
Cpp Exception std::runtime_error: abc
1666-
Cpp Exception myexception: My exception happened
1667-
Cpp Exception: The exception is an object of type 'char const*' at address xxx which does not inherit from std::exception
1663+
terminating with uncaught exception of type int
1664+
terminating with uncaught exception of type char
1665+
terminating with uncaught exception of type std::runtime_error: abc
1666+
terminating with uncaught exception of type myexception: My exception happened
1667+
terminating with uncaught exception of type char const*
16681668
'''
16691669

16701670
self.do_run(src, expected)

0 commit comments

Comments
 (0)