diff --git a/index.html b/index.html index 78d5bd7422dd4..5292ea2e9e70f 100644 --- a/index.html +++ b/index.html @@ -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) => { diff --git a/src/emscripten_exception.cpp b/src/emscripten_exception.cpp new file mode 100644 index 0000000000000..573f18071205c --- /dev/null +++ b/src/emscripten_exception.cpp @@ -0,0 +1,13 @@ +#if defined(EMSCRIPTEN) +#include + +std::string getExceptionMessage( intptr_t exceptionPtr ) +{ + return std::string( reinterpret_cast( exceptionPtr )->what() ); +} + +EMSCRIPTEN_BINDINGS( Bindings ) +{ + emscripten::function( "getExceptionMessage", &getExceptionMessage ); +} +#endif