Exception Handling
Exception handling is an important aspect of writing reliable, robust software. When a program encounters an error, such as a division by zero, an invalid input, or something such as AccountID not found
, it can generate an exception that can be caught and handled by the program. However, if exception handling is done poorly, it can lead to bugs, crashes, and other issues such as security issues whereby exceptions reveal valuable information to attackers and fraudsters. In this chapter, we’ll cover some best practices for clean exception handling in C#, including how to write code that is readable, maintainable, and testable.
The topics covered are the following:
- Overview of exception handling in C#
- Principles of clean code and how they relate to exception handling
- Best practices for handling exceptions, including logging, using
try
-catch
blocks, and handling specific exceptions - Creating custom exceptions and when to use them
- Avoiding...