为什么这个异常不会被跨DLL捕获? [英] Why is this exception not being caught across DLLs?

查看:300
本文介绍了为什么这个异常不会被跨DLL捕获?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DLL,它抛出一个异常,像这样:

I have a DLL which throws an exception like so:

throw POMException(err, drvErr, errmsg);

调用代码在一个单独的程序中,并有一个try,catch块, p>

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);
}

其中 TXNPDO_Exception 在包含的文件中定义:

Where TXNPDO_Exception is defined in an included file:

#define TXNPDO_Exception POMException

在调试器中运行时,它说明 POMException 未处理。我甚至添加了一个 catch(...)子句,它仍然没有处理。

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.

这与Visual C ++编译参数有关,因为所讨论的DLL库是一个传统的库,它是独立于程序调用它。我使用Visual Studio 2003。

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.

DLL cpp文件使用以下(相关)标志编译: / X / GR / Ob1 / Zi / GX / Od / MDd / LD

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?

编辑

DLL库之前是编译时可能的构建环境和代码更改, 。

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.

我使用相同的编译器编译客户端程序,使用大多数相同的开关: -Od -W3 -Z7 -MDd -GX -GR -Zm800 (无 / X / Ob1 / Z7 而不是 / Zi )。

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).

推荐答案

我终于找出了问题是什么,在这个特殊的情况下,它与DLL之间抛出异常无关。

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

由于在调用堆栈上进一步安装了异常处理程序挂钩,因此出现了问题。我通过添加try,catch(...)块到库中的每个级别,直到我发现异常没有传播的点。当我注释掉异常处理程序钩子注册代码,异常成功传播。

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.

这篇关于为什么这个异常不会被跨DLL捕获?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆