-
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
emscripten lacks standards-conforming C++ exceptions #2531
Comments
I suspect our personality routine might be having issues with polymorphic exceptions. Other possibly helpful documents: |
Ok, I plan on compiling libc++abi from source with debug symbols and linking against that. Then stepping through the above example while stepping through emscripten's build and seeing where they diverge. Suspect code. Also, cc @waywardmonkeys in case anything stands out. |
Not sure we handle virtual inheritance here. |
An exception that has virtual inheritance gets corrupted. This is demonstrated in the following test program; mangled_exception.cc: #include <cerrno>
#include <cstring>
#include <iostream>
#include <stdexcept>
#include <string>
//============================================================================
// :: Helpers
namespace
{
// A straight up derivation from std::runtime_error.
struct exception1: public std::runtime_error
{
// Construct with an errno value. The what() string will contain the
// std::strerror() string associated with the given error value.
explicit exception1(const int error)
: std::runtime_error(std::string("exception1: ")
+ std::strerror(error)),
m_error(error)
{}
// Access to our stored error value.
int error() const
{ return m_error; }
private:
// The errno value.
const int m_error;
};
// A virtual derivation from std::runtime_error.
struct exception2: public virtual std::runtime_error
{
// Construct with an errno value. The what() string will contain the
// std::strerror() string associated with the given error value.
explicit exception2(const int error)
: std::runtime_error(std::string("exception2: ")
+ std::strerror(error)),
m_error(error)
{}
// Access to our stored error value.
int error() const
{ return m_error; }
private:
// The errno value.
const int m_error;
};
void printException2(const exception2& ex)
{
std::cout
<< "exception2 with errno=" << ex.error() << " and what="
<< ex.what() << std::endl;
}
}
//============================================================================
// :: Entry Point
int main()
{
try {
throw exception1(EIO);
}
catch (const exception1& ex) {
std::cout
<< "Caught exception: " << ex.what() << " with error="
<< ex.error() << std::endl;
}
try {
const exception2 test(EIO);
printException2(test);
throw exception2(EIO);
}
catch (const exception2& ex) {
std::cout << "Caught exception: " << ex.error() << std::endl;
printException2(ex);
}
} To build use the following command:
When the generated JavaScript is run through node, the following output is observed:
Currently using a recent version of the incoming branches of emscripten:
|
This looks like a duplicate of #1546. |
Yes, different testcases in them though, so let's keep both open so we don't forget one. |
I believe I have managed to hook our exceptions catching decision code to use libcxxabi's |
…ust the pointer as an out param; fixes #2531; 1.21.9
Those last commits make use use libcxxabi's |
It seems the specific issue of catching std::exception has been fixed (in the incoming branch), but in general, C++ exceptions still aren't working.
Below is a small program that is based on one set of real, essential C++ exceptions from a real program. It exercises exception polymorphism, including in cases with virtual and multiple inheritence. Here are a few examples of the expected (g++) and actual (emscripten) output:
I can't really exercise most of the polymorphism cases because everything is falling into the "first catch" still.
By no means is this program an exhaustive test of all C++ exceptions, but it does demonstrate some of what is missing.
toolchain and emscripten (on the incoming branches):
test.cc
The text was updated successfully, but these errors were encountered: