How to Debug Exceptions
Exception is an error that occurs in runtime and typically breaks normal execution flow. JetBrains Rider allows you to effectively debug application exceptions: you can explicitly tell the debugger to suspend the program execution when any unhandled exception or an exception of a particular type is thrown. JetBrains Rider stops the execution right after the exception occurs (before any exception handling is run) allowing you to examine program's stack frames.
Debug user-unhandled exceptions
JetBrains Rider can break program execution when an unhandled exception is thrown and display the exception popup with the basic info about the exception at the code line that caused this exception. You can continue running the program, or explore more details in the Exception details tool window:
By default, JetBrains Rider does not break at unhandled exceptions. To enable this, use the following options on the Build, Execution, Deployment | Debugger page of the Settings/Preferences Ctrl+Alt+S:
Break on user-unhandled exceptions (.NET/.NET Core only)
Use this option to make the debugger stop on exceptions that are not handled within the code of the current solution.
For example: there is a callback to an external library, there is an exception thrown inside that callback, and the exception is handled in the library but not in your code. If this option is enabled, the debugger will stop on this exception.
Process exceptions outside of my code (.NET/.NET Core only)
Use this option to make the debugger stop on exceptions that are handled in library code.
If you do not need to stop in external code, it is recommended to keep this checkbox disabled because it can affect debugger performance, especially if external code throws lots of exceptions. This might be even more noticeable on macOS and Linux, where the .NET Core debug engine is relatively slow.
Break on unhandled exceptions
Use this option to break on exceptions that are handled neither in user code nor in library code. It is recommended to keep this option enabled because such exception will stop the application process anyway.
To debug an exception of a particular type, you should create a special exception breakpoint. Unlike line breakpoints, exception breakpoints are assigned not to a certain line of code, but to a certain exception type (for example, in case of C#, it can be any type inherited from the
Add an exception breakpoint
- Do one of the following:
Choosefrom the main menu.
Specify breakpoint properties. Note that if Just my code is enabled, the debugger will suspend the program only in case the exception is thrown by the user code.
Now, once the exception of the specified type is thrown, the debugger suspends execution.