Hey Sam,

> 
> Can you share the link flags you are are using for your project?    We know 
> this works in at least some cases because we have a test for it:
> 
> See:
> 
> https://github.com/emscripten-core/emscripten/blob/main/test/core/test_exceptions_primary.cpp
> 
> and:
> 
> https://github.com/emscripten-core/emscripten/blob/main/test/core/test_exceptions_primary.out
> 
> I imagine there is some issue with the settings you are using.
> 
> Do you get any kind of backtrace when you see the `Aborted(native code called 
> abort())` message?  Normally I would expect to see a backtrace?  Does happens 
> with you build with `-O0` vs `-O3`?  Any more information?

Sure, here's the stack:

Aborted(native code called abort())
antlr4-runtime-wasm.js:677
RuntimeError: Aborted(native code called abort())
    at abort 
(file:///Volumes/Extern/Work/projects/antlr4wasm/wasm/antlr4-runtime-wasm.js:696:11)
    at _abort 
(file:///Volumes/Extern/Work/projects/antlr4wasm/wasm/antlr4-runtime-wasm.js:6770:7)
    at invoke_v 
(file:///Volumes/Extern/Work/projects/antlr4wasm/wasm/antlr4-runtime-wasm.js:7777:29)
    at std::__terminate(void (*)()) 
(wasm://wasm/0503c22a:wasm-function[5703]:0xdaa23)
    at std::terminate() (wasm://wasm/0503c22a:wasm-function[5701]:0xdaa06)
    at std::rethrow_exception(std::exception_ptr) 
(wasm://wasm/0503c22a:wasm-function[3857]:0xb19ca)
    at invoke_vi 
(file:///Volumes/Extern/Work/projects/antlr4wasm/wasm/antlr4-runtime-wasm.js:7645:29)
    at antlr4::BailErrorStrategy::recover(antlr4::Parser*, std::exception_ptr) 
(wasm://wasm/0503c22a:wasm-function[2218]:0x405c6)
    at invoke_viii 
(file:///Volumes/Extern/Work/projects/antlr4wasm/wasm/antlr4-runtime-wasm.js:7667:29)
    at antlr4::BailErrorStrategy::recover(antlr4::Parser*) 
(wasm://wasm/0503c22a:wasm-function[2223]:0x40bc1)

And this is the build call:

em++ \
    wasm/antlr4-runtime-wrapper.cpp \
    antlr4-cpp-runtime/*.cpp\
    antlr4-cpp-runtime/atn/*.cpp\
    antlr4-cpp-runtime/dfa/*.cpp\
    antlr4-cpp-runtime/internal/*.cpp\
    antlr4-cpp-runtime/misc/*.cpp\
    antlr4-cpp-runtime/support/*.cpp\
    antlr4-cpp-runtime/tree/*.cpp\
    antlr4-cpp-runtime/tree/pattern/*.cpp\
    antlr4-cpp-runtime/tree/xpath/*.cpp\
    -O3\
    -std=c++17 -lembind -Iantlr4-cpp-runtime/ \
    -o wasm/antlr4-runtime-wasm.js\
    -s EXPORT_ES6=1\
    -s WASM=1\
    -s WASM_BIGINT=1\
    -s ALLOW_MEMORY_GROWTH=1\
    -s ASSERTIONS\
    -fexceptions\
    -g


I wonder why std::rethrow_exception calls std::__terminate in my code...

Btw. I saw that JS objects from exceptions thrown in C++ are different compared 
to all the other objects (no $$, no class handle etc). That makes it impossible 
to use `instanceof` to check for a particular exception type. I now have to 
check the exception name, which is a bit awkward. As you see I'm using JS 
exception support, not wasm exceptions, as the latter are a bit inconvenient 
with those tags to get details (I know there's getExceptionMessage, but that's 
not better than checking the JS exception object name).

On the other hand, if I throw a C++ exception in its JS incarnation, I get the 
normal object structure and `instanceof` works. Is this different behaviour 
intended?

For completeness I also tested with -swasm-exception and got this stack trace:

libc++abi: terminating
antlr4-runtime-wasm.js:1660
Aborted(native code called abort())
antlr4-runtime-wasm.js:677
RuntimeError: unreachable
    at __trap (wasm://wasm/04f49f3e:wasm-function[5811]:0xb7307)
    at ___trap 
(file:///Volumes/Extern/Work/projects/antlr4wasm/wasm/antlr4-runtime-wasm.js:7407:54)
    at abort 
(file:///Volumes/Extern/Work/projects/antlr4wasm/wasm/antlr4-runtime-wasm.js:706:5)
    at _abort 
(file:///Volumes/Extern/Work/projects/antlr4wasm/wasm/antlr4-runtime-wasm.js:6599:7)
    at abort_message (wasm://wasm/04f49f3e:wasm-function[5680]:0xb53bd)
    at demangling_terminate_handler() 
(wasm://wasm/04f49f3e:wasm-function[5681]:0xb54ed)
    at std::__terminate(void (*)()) 
(wasm://wasm/04f49f3e:wasm-function[5703]:0xb56b9)
    at std::terminate() (wasm://wasm/04f49f3e:wasm-function[5701]:0xb5692)
    at std::rethrow_exception(std::exception_ptr) 
(wasm://wasm/04f49f3e:wasm-function[3815]:0x92fd7)
    at antlr4::BailErrorStrategy::recover(antlr4::Parser*, std::exception_ptr) 
(wasm://wasm/04f49f3e:wasm-function[2178]:0x386ed)


Mike
-- 
www.soft-gems.net



Mike
-- 
www.soft-gems.net

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to emscripten-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/E09B6FEF-33E9-4E0F-95C1-F2A73CAD1EA3%40googlemail.com.

Reply via email to