Crash reporter for Emscripten sites - C++ exceptions in window.onerror

1 view
Skip to first unread message

Phil Endecott

unread,
Sep 25, 2025, 1:59:52 PM (3 days ago) Sep 25
to emscripte...@googlegroups.com
Dear Experts,

I'm trying to build a basic crash reporter for my Emscripten project.
I'll catch run-time errors and send some info to a server for logging.
Has anyone tried to do something like this before?

Currently, I have Javascript code that uses window.onerror. It gets
the error message string and posts it to the server. This basically works.

I'm trying to understand how errors of various sorts get from the
compiled C++ code to that window.onerror handler. In my tests:

- If an assert() fails in the C++ code, I get a useful error message
string.

- If the C++ code throws an unhandled exception, e.g. std::runtime_error("foo"),
then the message string in window.onerror is just a number. My guess
is that this is the numerical value of a const char* pointer that might
point to a useful message on the HEAP, but I haven't checked.

- If I dereference a null pointer, ... hmm, it's surprisingly difficult to
do that in a test, but I can call a null function-pointer, and that
gives me a useful error message.

Questions: is this a good approach? Where is the glue that joins
WASM to window.onerror? Are there hooks that I can use to change
the behaviour of that glue and get useful strings for uncaught
exceptions? Or should I look at the message and read the heap
myself if the message is just a number?


Thanks, Phil.




Reply all
Reply to author
Forward
0 new messages