Using exception handling
In this section, we’ll discuss what exception handling is, the two types of error handling, when to use error handling in an application, and how exceptions affect performance.
What is exception handling?
Exception handling is the ability to recover gracefully from unexpected situations in the code during runtime; how do we handle errors or problems we experience in applications? It also involves cleaning up allocated resources when issues occur to avoid memory leaks.
There are two types of errors:
- Runtime errors: These are unexpected errors we experience when running the application.
- Manual: These are intentional errors that are thrown based on a condition (for instance,
ArgumentNullException.ThrowIfNull()
at the beginning of a method to confirm whether a parameter is null or not).
Since this book focuses on intermediate to advanced developers, we’re assuming debugging an ASP.NET application is a common process; we...