Summary
In this chapter, we first understood why .NET embraced the exception model, in contrast to the error codes used by many other technologies.
The exception model has demonstrated that it is very powerful, providing an efficient and clean way to report errors to the call chain. It avoids polluting the code with additional parameters and error-checking conditionals, which may cause a loss of efficiency in certain cases. We also verified with a benchmark that the exception model must only be used for exceptional cases because otherwise, it may severely affect the application's performance.
We have also seen in detail the syntax of the try
, catch
, and finally
statements that allow us to intercept and handle the exceptions and provide a deterministic disposal of any outstanding resource.
Finally, we examined the diagnostics and logging options, which are extremely useful in providing all the necessary information to fix the bugs.
In the next chapter, we will be learning...