Resolved Exception not caught ?

cbreemer

Well-known member
Joined
Dec 1, 2021
Messages
184
Programming Experience
10+
This is probably a simple and/or dumb question. I have some code in a try/catch block but it still triggers an exception in VS2022, see image. The exception message is crystal clear, and kind of expected, but I fail to understand why it does not just execute my catch() code. Most likely I'm overlooking something obvious... Any ideas ?

ex.jpg
 
Debugger will break on exceptions unless you turn off breaking on specific exceptions:
1645960838584.png


Outside debugger the application will not stop (crash) at an exception thrown inside a Try-Catch.
 
The screenshot you posted literally tells you what's going on, as JohnH highlighted. The debugger will break when the exception is THROWN. In order for something to be caught, it needs to be thrown first.
 
As I recall there is a setting to only break when an exception is not caught, rather than when an exception is thrown.
 
Thanks all ! Somehow I knew it was a rookie question :oops: It's just that I have not actually run my program outside the debugger yet, or I would have noticed.
Also I seemed to remember my exception handlers WERE being triggered, but that may have been wishful thinking.
Breaking only when an exception is not caught seems a great option, I'll check that out. When I code an exception handler, I'd prefer the debugger not to preempt it.
 
Back
Top Bottom