在发布模式下无法捕获异常 [英] Can't catch exception in Release mode

查看:103
本文介绍了在发布模式下无法捕获异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我无法在程序的发布模式下捕获任何异常.但是调试模式可以正常工作,没有任何问题.我正在使用VS 2008作为我的IDE.

Hi,

I cant catch any exception in Release mode of my program. But debug mode is working fine w/o any problem. I am using VS 2008 as my IDE.

int _tmain(int argc, _TCHAR* argv[])
{
    try
    {
        printf("About to try\n");
        int j,i=20;
        j=i/0;
        *(char *)j = 0000;
        printf("Try done\n");
    }
    catch(...)
    {
        printf("Caught Exception\n");
    }
    printf("Waiting to stop\n");
    Sleep(5000);
    return 0;
}

推荐答案

除以零或访问无效的指针不会导致C ++异常.您可能需要查看结构化异常处理 [
Divison by zero or accessing an invalid pointer do not result in C++ exceptions. You may want to look at Structured Exception Handling[^]


问题在于被零除的问题不会发生.导致抛出C ++异常.如果您确实想捕获此类错误,则可以使用结构化异常处理 [ ^ ](或除C ++异常处理之外).
The problem is that divide by zero doesn''t cause a C++ exception to be thrown. If you really want to catch that kind of error you could use Structured Exception Handling[^] instead (or in addition to C++ exception handling).


感谢您的回复Nemanja Trifunovic和Graham Breach.

我发现了另一个编译器选项,在这种情况下可能会有所帮助.即C ++异常处理和结构化异常处理异常.

< a href ="http://msdn.microsoft.com/en-us/library/1deeycx5%28VS.80%29.aspx"> http://msdn.microsoft.com/en-us/library/1deeycx5%28VS.80%29.aspx</a> [< a href ="http://msdn.microsoft.com/zh-cn/library/1deeycx5%28VS.80%29.aspx" target ="_ blank "title =" New Window> ^</a>]
Thanks for reply Nemanja Trifunovic , Graham Breach.

I found another compiler option which may be helpful in such cases. ie C++ exception handling with structured exception handling exceptions.

<a href="http://msdn.microsoft.com/en-us/library/1deeycx5%28VS.80%29.aspx">http://msdn.microsoft.com/en-us/library/1deeycx5%28VS.80%29.aspx</a>[<a href="http://msdn.microsoft.com/en-us/library/1deeycx5%28VS.80%29.aspx" target="_blank" title="New Window">^</a>]


这篇关于在发布模式下无法捕获异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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