简体   繁体   中英

Why is this exception not being caught across DLLs?

I have a DLL which throws an exception like so:

throw POMException(err, drvErr, errmsg);

The calling code is in a separate program, and has a try, catch block like so:

try
{
    // function in separate DLL
}
catch (TXNPDO_Exception& e)
{
    SR_PERFLOG_MSG(SR_PERFMASK_SELECT, "ERROR selectInStages");
    TXNDBO_THROW(e);
}

Where TXNPDO_Exception is defined in an included file:

#define TXNPDO_Exception POMException

When running this in a debugger, it states that the POMException was unhandled. I even added a catch(...) clause and it still isn't handled.

I suspect that this has something to do with the Visual C++ compilation parameters, since the DLL library in question is a legacy library that is compiled separate to the program calling it. I am using Visual Studio 2003.

The DLL cpp files are compiled with the following (relevant) flags: /X /GR /Ob1 /Zi /GX /Od /MDd /LD . Other exceptions within the calling program are handled correctly.

Can anyone provide reasons why this exception isn't being propagated to the calling program?

Edit:

The DLL library was previously compiled with possible build environment and code changes that are not available to me. The previously compiled library propagates exceptions correctly.

I am compiling the client program using the same compiler, using mostly the same switches: -Od -W3 -Z7 -MDd -GX -GR -Zm800 (no /X or /Ob1 and /Z7 instead of /Zi ).

I would assume that throwing exceptions across .dll boundaries could only be possible, when the various .dll and program executable are compiled against the same C++ runtime, thus sharing the same heap. I could be wrong, but this is my best guess.

Edit:

I guess I wasn't wrong .

I have finally figured out what the problem is, and in this particular case, it is nothing to do with throwing exceptions between DLLs.

The problem is occurring due to an exception handler hook being installed further up the call stack. I diagnosed this by adding try, catch(...) blocks to every level in the library until I found the point at which the exception wasn't propagated. When I commented out the exception handler hook registration code, the exception was successfully propagated.

I now have to figure out the workings of exception handler hooks, which is outside the scope of this question. Thanks to everyone who shared their answers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM