0

I am getting the error "Vector subscript out of range". I know this means I've called a non-existant index in the vector. But how can I find the offending vector? The windows debugger doesn't seems to help much.

  • http://stackoverflow.com/questions/691719/c-display-stack-trace-on-exception – xiaofeng.li Apr 28 '16 at 01:28
  • 1
    If don't have access to (or don't like to work with) a debugger, you could just stub out big parts of your code until the error disappears, then revert one step, stub out smaller parts, and so on until you're staring at the relevant line. – Beta Apr 28 '16 at 01:31
  • 1
    An outside-the-box solution is to override vector with your own class that checks your index before calling the real Vector, and in the case of an out of range index, passed through code you've set a breakpoint on. – mah Apr 28 '16 at 01:35
  • You could change the vector `operator[]` to `.at()` calls and then trap the exception in your debugger. – M.M Apr 28 '16 at 02:15

1 Answers1

0

You run your program inside a debugger, and you ask that debugger to stop when the program encounters a fatal error (in every debugger I've seen, this is the default behavior). When the program crashes, you ask the debugger what line it was executing.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436