What is an assertion error in Microsoft Visual Studio? and unhandled exception access violation?

StackOverflow https://stackoverflow.com/questions/18578607

  •  27-06-2022
  •  | 
  •  

Question

What are assertion errors? I have read that it might be caused by a NULL value of a pointer being passed to function. I am reading a file from Visual Studio and I am sure this file exists. How can there be an assertion error?

Also, I have found an assert statement in my c program

assert(pred_dir<=2);

this code was downloaded from the internet (the reference software of h.264 video codec) from the internet and I am not quite sure how i would get an error like this. Sorry I could not post the source code because it is too big and consists of four projects. I only modified the code to read a textfile and got this error.

Also, what is an unhandled exception, access violation error?

Was it helpful?

Solution

An assertion is a condition that you, as a programmer, expect to be unequivocally true at a given point in the program. Many programming languages give you a way to assert a condition, and you, as a programmer, can use assertions to find and diagnose many problems before they happen.

For example, if at a specific point in your program, you expect a variable called a to be 0, you can write:

assert(a == 0);

and if during runtime, a is not 0 at that specific part of the program, you will get an artificial error, and the debugger will stop right there so you can diagnose your problem, and understand why a is not 0.

A very common assertion goes like

assert(some_pointer != NULL); // We already checked this before

In your specific example, a variable called pred_dir is expected to be less than or equal than 2. If you're getting an assertion error in there, it means that for some reason, pred_dir was greater than 2. Since the rest of the program is not expecting this, it makes no sense to keep on going, and the program will stop right there.

Please remember that assertions are a debugging aid to help you implement "sanity checks", and not as a way to display an error to a user. As such, you are encouraged to use lots of them when making your program, to make sure that all your assumptions about the state of your program are correct. If your program is correct, assertions should never stop the program.

Since assertions are a debugging aid, checking them makes no sense when you release your program for distribution to users. Therefore, many programmers turn off assertion checking when doing so. Many environments like Visual Studio automatically turn them off when creating a release build.

Check the wikipedia article, as it explains assertions in much more detail.

If an assertion is triggered on a released product, or a third-party library, it most likely means that there is an error in that program. If you are able to reproduce the problem, please report it to the author of the program.

OTHER TIPS

To answer the question: What are assertion errors?

If a programmer believe that a condition is so vital that it must always be true, and should not continue execution if the condition is found to be false, he can make an assertion. Which you posted a fine example of, if the condition (pred_dir<=2) returns true, then execution is continued as normal, but if it returns false, then the execution is halted and some indication is shown as to which assertion returned false.

Edit: Assertions can be used to debug your code or as stated simply used to halt execution if something VERY wrong happened.

This error might be caused because the Temp folder on your computer has read-only access control specified. Therefore, the Visual Studio .NET or Visual Studio 2005 Setup application cannot copy temporary installation files to your local hard disk.

Solution : To resolve this problem, remove the read-only access control for your Temp folder. To do this, follow these steps:

a) Locate the Temp folder on your computer.

b) Note Typically, this folder is located in C:\Documents and Settings\User Name\Local Settings, where User Name is your user name.

c) Right-click Temp, and then click Properties.

d) Under Attributes, click to clear the check box for Read-only.

Note : The Confirm Attribute Changes dialog box may appear (this behavior depends on the contents of your Temp folder). If this dialog box appears, click Apply changes to this folder, sub-folders and files, and then click OK.

e) Click OK.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top