Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
While debugging im getting "Unhandled Exception : Access Violation" How to solve it please help me


Thank you
AJ
Posted
Comments
Sergey Alexandrovich Kryukov 16-Mar-11 2:42am    
Who ask Questions like that? No information from you. How can you imagine the Answer?! Very bad.
Not to worry, read my instructions and proceed.
Next time, learn to report a problem properly.
--SA
fjdiewornncalwe 17-Mar-11 19:09pm    
He's getting an access violation because he probably isn't providing his code enough information either.
Sergey Alexandrovich Kryukov 17-Mar-11 22:14pm    
Very educated guess,
-SA

First of all, did you use debugger? It will pin-point the problem in almost all cases. Still have problems?

Handle all exceptions, at least on top of the stack of each thread. That will give you enough information to address the problem. If you still cannot solve it, dump exception information, stack, find out code lines where it happens, post relevant part of code (comment the lines where exception is thrown) and exception dump.

Don't block any exceptions from propagation up the stack, otherwise you will have huge troubles finding the ends. There are some rare exclusions from this rule when you really need to handle exceptions and block its propagation, usually as a work-around of some 3rd-party code inaccessible for your patch.

You can only block exception propagation on the very top of each thread and in the main UI cycle, always logging exception information (and presenting it in UI if it is in the UI thread). This is done to avoid termination of the application. You should have the exception dump in all cases.

If you cannot locate and fix the problem after you get this information, post it and ask follow-up Questions.

—SA
 
Share this answer
 
Comments
Espen Harlinn 16-Mar-11 16:25pm    
Good advice, my 5
Sergey Alexandrovich Kryukov 16-Mar-11 17:10pm    
Thank you, will probably re-use when non-.NET exceptions are involved (on .NET I already re-use a couple of past Answers)
--SA
Afzaal Ahmad Zeeshan 27-Jul-15 2:13am    
5ed, after reading this answer of yours it is pretty much clear to me as why you advised me to ignore using try catch and let exceptions be raised. Good one.
Sergey Alexandrovich Kryukov 27-Jul-15 2:21am    
Thank you, Afzaal.
—SA
You may want to use the following references to add some debugging functionality to your program:
Exception Handling in Visual C++[^]

_set_se_translator[^] - allows you to convert an access violation into a C++ exception - it's usually a good idea to preallocate a buffer for exception information on a per thread basis to avoid calling the runtime libraries during this conversion.

Possibly calling DebugBreak[^] as appropriate.

This usually facilitates more efficient debugging - especially if there is a lot of concurrent activity in your program.

Best regards
Espen Harlinn
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 16-Mar-11 17:19pm    
Quite good, a 5.
--SA
Espen Harlinn 16-Mar-11 17:25pm    
Thank you, SAKryukov!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900