-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[docs] Document limitation on std::set_terminate and __cxa_begin_catch #23728
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
Changes from 4 commits
3526475
b6f7831
c6940b2
591b4ad
d3b43e4
99bad19
b747cd2
e13ded9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,3 +171,40 @@ Using Exceptions and setjmp-longjmp Together | |
============================================ | ||
|
||
See :ref:`using-exceptions-and-setjmp-longjmp-together`. | ||
|
||
|
||
Limitations | ||
=========== | ||
|
||
* Currently `std::set_terminate | ||
<https://en.cppreference.com/w/cpp/error/set_terminate>`_ is NOT supported | ||
when a thrown exception does not have a matching handler and unwinds all the | ||
stack and crashes the program. This applies to both Emscripten-style and | ||
WebAssembly exceptions. That functionality requires `two-phase exception | ||
handling <https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html>`_, which | ||
neither supports. | ||
|
||
|
||
* When the exception handling encounters a termination condition, libc++abi | ||
spec says we call `__cxa_begin_catch()` to mark the exception as handled and | ||
then call `terminate()`. But currently Wasm EH does not support calling | ||
`__cxa_begin_catch()`. So the following program prints ``exception_ptr is | ||
null``, where it is supposed to print ``exception_ptr is NOT null``. | ||
|
||
.. code-block:: cpp | ||
|
||
#include <iostream> | ||
#include <exception> | ||
|
||
int main() noexcept { | ||
std::set_terminate([] { | ||
auto ptr = std::current_exception(); | ||
if (ptr) | ||
std::cerr << "exception_ptr is NOT null" << std::endl; | ||
else | ||
std::cerr << "exception_ptr is null" << std::endl; | ||
std::abort(); | ||
}); | ||
throw 3; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would writing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case there's no exception so |
||
} | ||
|
||
This can possibly be supported in the future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since both of these limitation are regarding
std::set_terminate
should we call this sectionLimitations regarding std::terminate
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done