Dan
Dan

Reputation: 2344

C++ out of range exception not firing

It's been a while since I've worked in C++ and I'm having some issues understanding why an out-of-range exception is not firing.

See the try below. I'm intentionally tripping it but in debug mode, it's breaking on that line, rather than falling into the catch as I would expect.

Nothing I've read over the last hour has made me any wiser to the issue.

enter image description here

Upvotes: 0

Views: 358

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 596332

By design, a debugger sees all exceptions before the executable code does. This allows you to analyze and potentially fix any problems related to the exception before continuing, or to just end execution, etc.

To let the catch work inside a debugger, simply tell the debugger to continue execution once it breaks on an exception, and the exception will then be passed to the executable code for normal handling.

When the code is run outside of a debugger, the exception will just go straight to the nearest matching catch as expected.

Upvotes: 4

Related Questions