In this chapter, we take a concise look at error-handling techniques in VB.NET. Note that the terms exception and error are used synonymously throughout the VB.NET documentation, and so we use them interchangeably in this chapter.
VB.NET supports the
Goto style of error handling, which is supported
by earlier versions of Visual Basic (with some new wrinkles). This
type of error handling is referred to as unstructured error handling. However, unlike earlier versions of Visual
Basic, VB.NET also supports the structured exception handling technique familiar to C++ programmers, which is
now the preferred method of error handling in VB.NET.
Let us begin by clarifying some terminology. We agree to say that handling an error means responding to a detected error. Thus, there is a clear distinction between error detecting and error handling. The reason for this distinction is that these processes can take place at different times and in different locations within the code of an application. We also agree to refer to the procedure (or module) in which an error occurs as the offending procedure (or module).
There are two types of errors that can occur in a running program. (We will not discuss compile-time or syntax errors.) A runtime error occurs when Visual Basic attempts to perform an operation that is impossible to perform, such as opening a file that does not exist or dividing by 0. Visual Basic automatically ...