简体   繁体   中英

How do I find the location of a "vector subscript out of range" error? C++ Visual Studio

I am quite new to coding. I know what "vector subscript out of range" means, how it occures and how to fix it. But I have many many vectors in my code and often get this error. But when this error hits I always get this error box you all know. And it says "Hit retry to debug your application". And when I click it it brings me to line 1731 in the "vector" file. But how do I get to the point (the line or the file) in my code, where I created this error???

I tried using the Debug-Navigation in VisualStudio to move back and forth to get to my code. But this doesn't work. Thanks for your help in advance.

You should be able to find the problematic place from the call stack. There you can go up and down the stack by double-clicking the corresponding line and check the Autos and Locals debugging windows ( https://learn.microsoft.com/en-us/visualstudio/debugger/autos-and-locals-windows?view=vs-2022 ).

The problem you might have is that you are getting into the debugger too late, when the exception is unhandled (there were no try/catch blocks able to handle this, so it was caught by the C++ infrastructure). Check Debug->Windows->Exception Settings window and set the exception you get to break when the exception is thrown (not unhandled).

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