0

So I'm a new user of vscode and I love the IDE and I'm using it for c++ specifically. My problem is that I want to be informed of exactly where a mistake is hence the line number where the program terminated during an error. Basically I got an error like this:

"terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 18446744073709551615) >= this->size() (which is 5)"

It doesn't tell me where the termination occurred I would like to know the last line that was executed to cause this error without needing to debug. If there is any way please let me know.

rioV8
  • 24,506
  • 3
  • 32
  • 49
  • 2
    https://stackoverflow.com/questions/691719/c-display-stack-trace-on-exception – Joop Eggen Aug 17 '22 at 05:43
  • Run the program in the debugger. The debugger will halt and allow you to inspect the crash site when the exception is thrown and not caught. – user4581301 Aug 17 '22 at 05:54
  • Mind you, it looks like you fed -1 or `npos` into `at`. Make sure you don't have `at(i-1)` where `i` can be zero or `somestring.at(somestring.find(something_not_found))` – user4581301 Aug 17 '22 at 05:56
  • Also be wary that the cause of the bug might not be at the crash site. It could be a mistake made earlier that finally becomes fatal at the call to `at`. – user4581301 Aug 17 '22 at 05:58
  • Hi definitely! I know the cause is because it calls for a space that's not within the array bounds. I just wanted to know the last line of execution on the run fail instead of debugging and going through each line of code you know what I mean? like wouldn't it be nice to have last line exec 55? So you can just see what's going on. – AceJoker Studio Aug 21 '22 at 07:37
  • You want a stacktrace. See the link from Joop Eggen. A stacktrace shows the position, where the exception occurred, including, which code called the failing function, and so on. – Sebastian Aug 21 '22 at 08:19

1 Answers1

0

So basically I have figured out the best way is to just debug the code. So when you run debug for c++ you will see that on the left debug panel it will actually show that you can leave breakpoints on classes and exceptions. So you just check the box that says All exceptions. What that does is pause on the first line of code that gives that exception. So it will basically stop on the line that throws that error. Also, stacktrace is a way however it just seemed too complicated at the time for me to implement.