-
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
Feature suggestion: C++ exception formatting #16326
Comments
Seems like a good idea yes. One problem we have is that we don't normally control the exception handler on a given web-page so it would still be the responsibility of the page author use these helpers to format the exception (I think). But having the helpers available certainly makes sense to me. |
Yes this makes sense to me too. I can open a PR then. Would the C++ code for this go under |
We always prefer native code where possible. Rule of thumb is to only call out the JS if it can't be done in native. Somewhere in system/lib makes sense yes.. |
Well this functionality is meant to be called from Javascript I think, so the outermost layer has to be in Javascript. We could do most of the stuff in a function like: extern "C" char *format_exception(void *exc); and then we would still need a Javascript wrapper to convert the return value: function formatException(ptr){
var msg_ptr = _format_exception(ptr);
var msg = UTF8ToString(msg_ptr);
_free(msg_ptr);
return msg;
} |
Sounds like that sounds reasonable yes. (If you use stackAlloc and pass in the buffer size you can avoid pulling in a malloc/free dependency). |
I think I can't avoid malloc altogether without also avoiding See the
|
Fair enough. BTW, why do you need to call __cxa_demangle? |
IIRC, __cxa_demangle is a fairly costly function in terms of code size, so big that we don't include it by default and you need to opt in with |
Well I think the nicest thing would be to have
To get
|
Sounds good! |
If there is an uncaught C++ exception, it prints a message like
Uncaught 13777136
, which isn't super useful. I want a function to convert the pointer into a more user friendly message like:CppException myexception: My exception happened
or:
CppException int: An object of type int at address 15738976 was thrown as a C++ exception
This seems like something that could be added to Emscripten. WDYT? Also, I have no clue how wasm-exceptions work and whether the code would need to be different for that case, but if you are interested in adding a feature like this, I would be willing to figure it out.
I wrote the following code for this:
Details
C++
Typescript
The text was updated successfully, but these errors were encountered: