在C ++中,任何try catch都会在.exe中捕获未处理的异常:0xc0000005:访问冲突 [英] In C++ any try catch to catch unhandled exception at address in .exe: 0xc0000005: access violation

查看:490
本文介绍了在C ++中,任何try catch都会在.exe中捕获未处理的异常:0xc0000005:访问冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





在长时间运行后的c ++程序中,我认为在内存中出现错误。错误显示

Hi,

In c++ program after long run I am getting an error at memory i think. The error shows

Unhandled exception at [address] in [projectname].exe: 0xc0000005: Access violation.



有没有办法用try catch来处理这个问题。这使我的应用程序崩溃。请帮助我谢谢。



我尝试过的事情:




Is there any way to handle this issue with try catch. This make my application to crash. Please help me on this thank you.

What I have tried:

Unhandled exception at [address] in [projectname].exe: 0xc0000005: Access violation.

推荐答案

启用SEH时可以捕获此类异常(结构化异常处理,请参阅 - EH(异常处理模型) [ ^ ])。



因为这些异常是异步的,所以它们是致命错误,应用程序应该终止。因此,除了生成您自己的错误消息或记录它们之外,捕获此类异常对发布版本没有任何好处。



但是您可以暂时使用它们来更接近源代码通过在显着的代码位置插入try catch块来解决问题。一旦你有一小部分代码抛出异常,检查它以找到可能的来源。



如果到目前为止没有完成,请确保所有指针变量都已初始化并且执行 assert()检查调试版本。



要记下来:

您的代码中存在必须修复的错误。它通常可以通过捕获由于异步引起的异常来处理。
You can catch such exceptions when enabling SEH (structured exception handling, see -EH (Exception Handling Model)[^]).

Because such exceptions occur asynchronous, they are fatal errors and the application should terminate. So catching such exceptions has no benfits for release builds besides generating your own error message or logging them.

But you can use them temporarily to get closer to the source of the problem by inserting try catch blocks at prominent code locations. Once you have a smaller portion of code that throws the exception, inspect it to find probable sources.

If not done so far, ensure that all pointer variables are initialised and perform assert() checks for debug builds.

To nail it down:
You have a bug in your code that must be fixed. It can be generally handled by catching the exception due to the asynchronism.


这是一个内存访问冲突。您的程序正在访问无效内存。通常是一个误导性指针:已删除的内存或错误地设置或使用指针。



您必须调试发生它的代码行。我知道Visual Studio中的一个选项可以在内存或值发生变化时点击调试点,但不记得它现在在哪里...(对不起)



阅读使用断点:附加信息找到设置方法有用的断点和调试。
This is a memory access violation. Your program is accessing invalid memory. Normally a misleading pointer: deleted memory or the pointer is set or used wrongly.

You must debug the code line in which it happens. I know an option in Visual Studio to hit a debug point when memory or a value is changed, but not remember where it is now... (sorry)

Read the Using Breakpoints: Additional Information to find a way to set a helpful breakpoint and debug.


您还应该考虑使用DbgHelp.DLL库(至少在调试版本中)。给定调试信息和符号,它可以用于从引发异常的位置开始创建堆栈跟踪。
You should also look into using the DbgHelp.DLL library (at least in debug versions). Given debug information and symbols, it can be used to create a stack trace starting at the point where the exception was raised.


这篇关于在C ++中,任何try catch都会在.exe中捕获未处理的异常:0xc0000005:访问冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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