I have a small issue. Sometimes when I debug an application I want to simulate during the debug session an exception thrown from a method, but there is no way to do it. I can't even drag the cursor (the yellow one that indicate the current line) to an exception block. The only way to trigger an exception during the run is to change the current line of code and to write the exception I want to throw. This method is not good because I might forget to change it back in the next run.
You can also click on the line you want to skip to and hit Ctrl+F10 (Run to Cursor). It will jump directly to that line.
Exception handling is all about ensuring that when your program encounters an issue, it will continue to run and provide informative feedback to the end-user or program administrator.
With a solution open in Visual Studio, use Debug > Windows > Exception Settings to open the Exception Settings window. Provide handlers that respond to the most important exceptions.
The only really workable way I have found to throw exceptions from within a method during debugging is to pull variable from under the feet of the executing process. I.e. set a variable that is about to be used to null will obviously throw an exception as soon as it is executed. However this will not allow you to throw custom exceptions (e.g. specific types or messages).
For specific exceptions we need to modify code according to previous posts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With