Skip to content

Commit

Permalink
Add some basic exception reporting for emscripten
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon committed Feb 19, 2024
1 parent 910d417 commit dfc3ddd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion build-data/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,10 @@
},
};
Module.setStatus("Downloading...");
window.onerror = function (event) {
window.onerror = function (event, source, lineno, colno, error) {
if (typeof error === 'number' && Module.getExceptionMessage) {
console.log(Module.getExceptionMessage(error));
}
alert("Exception thrown, see JavaScript console.");
};
window.onbeforeunload = (e) => {
Expand Down
13 changes: 13 additions & 0 deletions src/emscripten_exception.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#if defined(EMSCRIPTEN)
#include <emscripten/bind.h>

std::string getExceptionMessage( intptr_t exceptionPtr )
{
return std::string( reinterpret_cast<std::exception *>( exceptionPtr )->what() );
}

EMSCRIPTEN_BINDINGS( Bindings )
{
emscripten::function( "getExceptionMessage", &getExceptionMessage );
}
#endif

0 comments on commit dfc3ddd

Please sign in to comment.