访问冲突读取位置异常

访问冲突读取位置异常

本文介绍了访问冲突读取位置异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个简单的问题:


为什么以下代码没有捕获Access违规读取位置异常?


它崩溃了if(xyz)与Access违规读取位置异常的行。是不是应该赶上它?实际上,它没有。

A quick question:

Why doesn''t the following code catch the Access violation reading location exception?

it crashes on line if ( xyz ) with an Access violation reading location exception. Is not catch supposed to catch it? Practically, it doesnt.

展开 | 选择 | Wrap | 行号

推荐答案




此代码不会在上崩溃语句,如果xyz是指针。 if 语句仅对true或false进行测试,并且不访问指针中的位置。


可能发生的事情是你从未初始化xyz所以它是非零(因此是真的)但包含垃圾值。那会让你失望。

This code shouild not crash on the if statement if xyz is a pointer. The if statement does a test for true or false only and does not access the location in the pointer.

What can happen is that you never initialized xyz so that it is non-zero (hence true) but contains a garbage value. That will bring you down.




我也很惊讶它在if语句中崩溃了。


更容易理解崩溃在xyz-> ID ......


但由于某种原因它在if语句中崩溃了。它肯定是通过这种方式初始化的。

I am surprised too that it crashes at if statement.

it is more understandable crashing at xyz->ID ...

but it crashes at if statement for some reason. It is definitely initialized by the way.


这篇关于访问冲突读取位置异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 06:50