-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Misleading C++ exception handling example #19764
Comments
IIUC when you build with |
@sbc100 The The following flags are NOT set: function ___cxa_throw(ptr, type, destructor) {
var info = new ExceptionInfo(ptr);
info.init(type, destructor);
exceptionLast = ptr;
uncaughtExceptionCount++;
throw exceptionLast;
} In the code where we want to guess the exception message, it is something like this (where _call(f) {
return (...params) => {
try {
return f(...params);
} catch (e) {
if (Number.isInteger(e)) {
let address = parseInt(e, 10);
let cMessage = this.module._vizzu_errorMessage(address); // getExceptionMessage
let message = this.module.UTF8ToString(cMessage);
throw new Error("error: " + message);
} else {
throw e;
}
}
};
} You need to set the |
I see, so your code is working correctly, this is simply a request to clarify the documentation? Perhaps @aheejin has some thoughts on this? |
It seems like that documentation should be updated since now we have Can you explain a little more what you mean by "we don't have a bound __get_exception_message:" What happens if you use the function? I guess because RTTI is missing you don't get things like |
When we set the When we attempted to enable the It is likely that the condition in this section is not properly configured. Instead of checking the disabled catching, it should examine the disabled throwing flag. |
I think you likely correct. Perhaps it can be confusing because that In any case.. this seems worth fixing. |
I can make |
Won't the code size increases will only effect those who opt into Function that get added to |
emscripten-core#19764 pointed out that the docs on `getExceptionMessage` was outdated. We don't need to implement a custom `getExceptionMessage` anymore. Fixes emscripten-core#19764.
But if I build a program using emcc -fwasm-exceptions -sEXPORT_EXCEPTION_HANDLING_HELPERS test.cpp -o test.js Then |
Oh, that might be because In any case, anyone who opts into |
#19764 pointed out that the docs on `getExceptionMessage` was outdated. We don't need to implement a custom `getExceptionMessage` anymore.
@aheejin This solution only works when we switch on the And another problem is that this switch adds 50k size to the binary which is unacceptable to our users. |
I think there is some confusion here.. and perhaps it is mine, but IIUC Perhaps you thought that because @aheejin used |
It is not working as I wrote in my upper comment:
|
Can you reopen it, or should I create a new ticket? |
We can consider allowing |
I replaced emcc.py:2908 library_exceptions.js:313 and library_exceptions.js:400 to check for The So we need only the |
Yeah right. That was meant to give some more info on the type of the exception, especially in case the exception is not a subclass of |
It sounds like that are two different issues. Firstly that this doesn't currently work, and secondly that it adds a lot of code size. I suggest we fix the first issue first, and with a test. Then we can separately consider how to add a non-demanding version. I'm somewhat averse to adding this extra complexity.. I would love it is there was way to do it without adding a separate. Perhaps we can find a way to have it controlled by the existing |
No it currently works as intended. The intention was
It doesn't seem to work, because the demangling function is used by |
What I meant was that we could perhaps have |
We can probably do that, but that's gonna increase one more dimension for the variations for the library builds. We already have |
Could we make two versions of |
Like, you call different versions in JS based on the option? I think we could... but not sure how large the demand would be. |
Version of emscripten/emsdk:
Documentation - all version from here.
According to the documentation, this code snippet appears to be a handler function for getExceptionMessage. However, it is much simpler than the current implementation found here.
The documentation also mentions that "this example code will only work for thrown statically allocated exceptions" but in reality, it only works if the exception type is exactly
std::exception
. It will not work (according to the standard C++) if the exception is a child ofstd::exception
becauseis_pointer_interconvertible_base_of_v<std::exception, std::[any other std exception]>
evaluates to false. Therefore, the reinterpret casting is not safe and results in undefined behavior.Another issue is that this code can be exploited using the following structure:
We are using Emscripten with the following switches:
-s DISABLE_EXCEPTION_CATCHING=1 -fno-rtti
. This means that we don't have a bound__get_exception_message
, but we still have exceptions and we want to retrieve the reason using.what()
. We thought that this code snippet would be sufficient for handling.what()
, but it turns out it's not. Therefore, this part of the documentation is misleading.The text was updated successfully, but these errors were encountered: