WHAT'S IN THIS CHAPTER
The general principles behind exception handling
The Try...Catch...Finally structure for trapping exceptions
Obtaining information about an exception by using the exception object's methods and properties
How to send exceptions to other code using the Throw statement
Event logging and simple tracing, and how you can use these methods to obtain feedback about how your program is working
All professional-grade programs need to handle unexpected conditions. In older programming languages this was often called error handling. Unexpected conditions generated numeric error codes, which were trapped by programming logic that took appropriate action.
The common language runtime in .NET does not generate error codes. When an unexpected condition occurs, the CLR creates a special object called an exception. This object contains properties and methods that describe the unexpected condition in detail and provide various items of useful information about what went wrong.
Because the .NET Framework deals with exceptions instead of errors, the term error handling is rarely used in the .NET world. Instead, the term exception handling is preferred. This term refers to the techniques used in .NET to detect exceptions and take appropriate action.
This chapter covers how exception handling works in Visual Basic 2010. It discusses the common language runtime (CLR) exception handler in detail and the programming methods that are most efficient ...