Repository navigation
Adds 'throw_' method to val - #7405
Conversation
|
Looks good to me -- I think those CI test fails are just transitory failures of the browser-based tests. |
|
I'll throw in my 👍 too. :) I forget - do JavaScript exceptions thrown from C++ cause C++ destructors to unwind? |
|
@chadaustin they should - calls become invokes, which catch any JS exception. |
As mentioned in emscripten-core#6330. Something like this will now work: val::global("TypeError").new_("wrong type").throw_(); In the tests found in test_val.cpp it can be seen that an error can be thrown in CPP and successfully caught in JS.
|
@robfors do you have an example i tried |
|
I fixed the mistake in my example. Thanks for pointing that out. |
|
when i tried this val::global("Error").new_(val("wrong type")).throw_();I got Sorry, I'm still kinda new to emcc |
|
That is strange. If it helps at all, you can also refer to the tests for some examples. They can be run with |
|
Hi folks, I realise this is quite old, but from what I can tell, calls to |
|
In fact, it seems the very throw statement might be leaking memory? val::global("TypeError").new_(val("wrong type")).throw_();creates a new object, the handle to which is stored in the [[noreturn]] void throw_() const {
internal::_emval_throw(handle);
}This already tells us that we're not coming back, but looking deeper, we have |
As mentioned in #6330.
Something like this will now work:
In the tests found in
test_val.cppit can be seen that an error can be thrown in CPP and successfully caught in JS.