Why does this exception not get into the DLL?

I have a dll that throws an exception like:

throw POMException(err, drvErr, errmsg); 

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

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

Where TXNPDO_Exception defined in the included file:

 #define TXNPDO_Exception POMException 

When running this, the debugger indicates that a POMException was unhandled. I even added a catch(...) clause and it is still not being processed.

I suspect that this has something to do with Visual C ++ compilation options, because the DLL under consideration is an outdated library that is compiled separately from the program that calls it. I am using Visual Studio 2003.

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

Can someone explain the reasons why this exception does not apply to the calling program?

Edit:

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

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

+4
source share
2 answers

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

The problem arises because the hook of the exception handler is set further on the call stack. I made the diagnosis by adding try, catch (...) blocks to each level in the library, until I found the point at which the exception was not propagated. When I commented on the hook code of the exception handler, the exception was successfully thrown.

Now I need to find out the work of exception handlers that go beyond the scope of this question. Thanks to everyone who shared their answers.

+1
source

I would suggest that throwing exceptions across .dll boundaries was only possible when different DLLs and executables were compiled against the same C ++ runtime, thus using the same heap. I could be wrong, but this is my best guess.

Edit:

I think I was not wrong .

+2
source

Source: https://habr.com/ru/post/1384221/


All Articles