简体   繁体   English

为什么不会在DLL中捕获此异常?

[英]Why is this exception not being caught across DLLs?

I have a DLL which throws an exception like so: 我有一个DLL抛出异常,如下所示:

throw POMException(err, drvErr, errmsg);

The calling code is in a separate program, and has a try, catch block like so: 调用代码在一个单独的程序中,并有一个try,catch块,如下所示:

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: 在包含的文件中定义TXNPDO_Exception

#define TXNPDO_Exception POMException

When running this in a debugger, it states that the POMException was unhandled. 在调试器中运行它时,它指出POMException未处理。 I even added a catch(...) clause and it still isn't handled. 我甚至添加了一个catch(...)子句,但仍未处理。

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. 我怀疑这与Visual C ++编译参数有关,因为所讨论的DLL库是一个遗留库,它是与调用它的程序分开编译的。 I am using Visual Studio 2003. 我正在使用Visual Studio 2003。

The DLL cpp files are compiled with the following (relevant) flags: /X /GR /Ob1 /Zi /GX /Od /MDd /LD . DLL cpp文件使用以下(相关)标志进行编译: /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. 之前使用可能的构建环境和代码更改编译了DLL库,这些更改对我来说是不可用的。 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 ). 我正在使用相同的编译器编译客户端程序,主要使用相同的开关: -Od -W3 -Z7 -MDd -GX -GR -Zm800 (no /X/Ob1/Z7而不是/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. 我假设只有在相同的C ++运行时编译各种.dll和程序可执行文件时才能跨越.dll边界抛出异常,从而共享同一个堆。 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. 我终于弄明白了问题是什么,在这种特殊情况下,它与在DLL之间抛出异常无关。

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. 我通过向库中的每个级别添加try,catch(...)块来诊断这一点,直到找到未传播异常的点。 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. 感谢所有分享他们答案的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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