简体   繁体   中英

How to find the location where exception occurred in VS C++

I am getting this exception:

Microsoft C++ exception: std:out_of_range at memory location 0xBlahBlahBlah

How can I find this location in my code?

One way is to enable the "Break When Thrown" for everything in the Exception Settings. It will have a list of exception types that can be turned on via checkboxes. I usually will turn them all on and go. You may get a few handled exceptions along the way but you shouldn't miss the problem one.

You can find it under: Debug->Windows->Exception Settings

Once you're done, I recommend returning it to its default settings (there's a graphical button for it) so you don't keep breaking every time a handled exception is thrown.

Here are problem resolution steps:

  1. Find memory location displayed in "exception: EEEE at memory location 0xXXXXX" location In disassembly window.
  2. Set breakpoint at that location and run program until it breaks.
  3. Check call stack to find the function that actually threw the exception.

For some reason debugger did not break when std::out_of_range exception was thrown even though debugger exception settings were set to break when std::exception was thrown.

My approach is setting up a break point somewhere, and then press keep pressing F10 until it throw the exception. Now you know where the bug is.

This error is a run time logical error which can happen in many cases and to find it you should trace your code and look for some logical errors. eg

int x[4];
x[5] = 1;

int this case you are using a memory unit which is not allowed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM