Skip to content
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

Cross-module exception handling #4668

Open
siren186 opened this issue Sep 9, 2024 · 0 comments
Open

Cross-module exception handling #4668

siren186 opened this issue Sep 9, 2024 · 0 comments

Comments

@siren186
Copy link
Member

siren186 commented Sep 9, 2024

Hi @obiltschnig

I encountered a very subtle issue. It is about Poco::Exception in PocoFoundation64.dll. In Visual Studio 2019/2022 release_shared x64.
It is very hard to reproduce. Due to the large amount of code, I can't paste it all here, so I’ve only extracted a small portion.

// This is a small portion I extracted from a large amount of code.
int main() {
    std::uint64_t val = 0x1122334455667788;
    
    try {
    	throw Poco::Exception("error"); 
        // If I do not use Poco::XXXXXXException, everything works fine.
        // throw std::exception("error"); // It's OK !!!
    } catch (const Poco::Exception& e) {
    }
    
    std::cout << val; // Now the val is 0x1122334400000000 !!!
    // It's Very Strange !!! It lost low 32 bit.
    return 0;
}

It took me two days to find the real reason.

auto m = sizeof(Poco::Exception);
auto n = sizeof(std::exception);

// m=72, n=24: In PocoFoundation64.dll
// m=64, n=16: In my EXE

It was all caused by _HAS_EXCEPTIONS=0 in my EXE compile options. This macro will change the class size and implementation of std::exception.

// By: _HAS_EXCEPTIONS=1 (default in visual studio)
// sizeof(std::exception) == 24
namespace std { 
    class exception {
    public:
        virtual ~exception() {}
    private:
        char const* _What;
        bool        _DoFree;
    }
}


// By: _HAS_EXCEPTIONS=0
// sizeof(std::exception) == 16
namespace std { 
    class exception {
    public:
        virtual ~exception() {}
    protected:
        const char* _Ptr;
    }
}

I think it's necessary to add some tips in POCO documentation to avoid users wasting unnecessary time on this issue.


See alse: nodejs/node-addon-api#85

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant