Skip to content

std::uncaught_exception() is true after the exception has been caught #11776

Closed
@ImplOfAnImpl

Description

@ImplOfAnImpl

In the following code std::uncaught_exception() returns true when it shouldn't:

// ems_test.cpp
#include <exception>
#include <iostream>

struct Base
{
    virtual ~Base() {}
};

struct Exception: public Base, public std::exception
{
};

int main()
{
    try
    {
        throw Exception();
    }
    catch (const std::exception&)
    {
    }

    if (std::uncaught_exception())
    {
        std::cout << "!!! Not OK" << std::endl;
    }
    else
    {
        std::cout << "OK" << std::endl;
    }
}
$ em++ -s DISABLE_EXCEPTION_CATCHING=0 -o ems_test.js ems_test.cpp && node ems_test.js
!!! Not OK

I've run the code in a debugger and noticed that __cxa_begin_catch receives the 'adjusted' version of the exception pointer, which is not among the keys in exceptionInfos. So probably it should first be de-adjusted with exception_deAdjust (it worked for me).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions