无法捕获c ++异常使用catch(...) [英] Unable to catch c++ exception using catch (...)

查看:212
本文介绍了无法捕获c ++异常使用catch(...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个第三方库,有时会抛出异常。所以我决定将我的代码包装在一个try / catch(...),以便我可以记录有关异常发生(没有具体的细节,只是它发生了。)

I have a third-party library that is sometimes throwing an exception. So I decided to wrap my code in a try/catch(...) so that I could log information about the exception occurring (no specific details, just that it happened.)

但是由于某种原因,代码仍然崩溃。在客户端计算机上,它崩溃了,用于记录异常在catch(...)中的代码永远不会被执行。如果我在我的调试/开发机器上运行这个,我得到弹出询问我是否要调试。当我这样做,它报告0xC0000005:访问冲突读取位置XXX。

But for some reason, the code still crashes. On client computers, it crashes hard and the code to log the exception in the catch(...) never gets executed. If I run this on my debug / development machine I get the popup asking me if I want to debug. When I do this, it reports 0xC0000005: Access violation reading location XXX.

奇怪的是,使用旧版本的第三方库,完全相同的代码DOES捕获异常,并且代码记录异常执行。

The odd thing is that with an older version of the third-party library, the exact same code DOES catch the exception, and the code to log the exception DOES execute. (I verified this within VS watching the same conditions occur.)

以下是正在执行的伪代码:

Here's the pseudo-code that is executing:

pObject = pSystem->Get_pObject()
pSystem->DoSomethingThatMightDestroy_pObject();
try
{
	/*   Call to third party function that is throwing exception */
	pObject->SetValue(0);
}
catch (...)
{
	__DEBUG_LOG_POSITION__;  // A macro to log the current file line
	//  This code used to run in the older version of third-party library
	//  but the newer version just crashes before running the catch(...)
}

所以我有两个问题:


  1. 第三方编译库的方式是否有所改变,使我的代码无法捕获异常? (是的,有一个机会,我可以让第三方做任何必要的修正,并重新编译我,如果我知道该告诉他们。)

  1. Is there some change in the way the third party might have compiled the library so that my code wouldn't be able to catch the exception? (Yes, there is a chance I can get the third party to make whatever fixes are necessary and recompile for me, if I know what to tell them.)

假设我不能让第三方修复它,我能做些什么来捕获这些异常?我正在考虑...是否有一些方法可以确定pObject是否已被释放?

Assuming I can't get the third party to fix it, what can I do to catch these exceptions? I'm thinking along the lines of... is there some way for me to determine whether pObject was deallocated?


推荐答案

AFAIK访问冲突不会抛出异常...至少不是标准的!

AFAIK access violation don't throw exception... at least not standard ones!

可能会捕获特定于Windows的原生异常将有助于: http://www.gamedev.net/reference/articles/article2488.asp

Maybe catching windows-specific "native" exception would help : http://www.gamedev.net/reference/articles/article2488.asp

这篇关于无法捕获c ++异常使用catch(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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