如何处理Visual Studio C ++中的访问冲突? [英] How can I handle an access violation in Visual Studio C++?

查看:1217
本文介绍了如何处理Visual Studio C ++中的访问冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,访问冲突终止程序,我无法使用 try catch 捕获Win32异常。有没有办法让我的程序运行,即使在访问冲突的情况下呢?最好我想处理这个异常并向用户显示发生访问冲突。

Usually an access violation terminates the program and I cannot catch a Win32 exception using try and catch. Is there a way I can keep my program running, even in case of an access violation? Preferably I would like to handle the exception and show to the user an access violation occurred.

编辑:我希望我的程序非常强大,甚至编程错误。我真的想避免的是一个程序终止,即使是一些损坏的状态的代价。

I want my program to be really robust, even against programming errors. The thing I really want to avoid is a program termination even at the cost of some corrupted state.

推荐答案

在Windows中,这称为结构化异常处理(SEH)。详情请见:

In Windows, this is called Structured Exception Handling (SEH). For details, see here:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms680657%28v=vs.85%29.aspx

实际上,当发生异常时,您可以注册获取回调。您不能为此出现任何异常,显而易见的原因。

In effect, you can register to get a callback when an exception happens. You can't do this to every exception for obvious reasons.

使用SEH,您可以检测到很多异常,包括访问冲突,但不是全部(例如双堆栈故障)。即使可以检测到异常,除非例外,否则无法确保100%的稳定性。但是,通知用户可能已经足够了,记录错误,将消息发回服务器,并正常退出。

Using SEH, you can detect a lot of exceptions, access violations included, but not all (e.g. double stack fault). Even with the exceptions that are detectable, there is no way to ensure 100% stability after the exception. However, it may be enough to inform the user, log the error, send a message back to the server, and gracefully exit.

这篇关于如何处理Visual Studio C ++中的访问冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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