O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 9. Error Handling in VB.NET

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 On Error 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.

Error Detection and Error Handling

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required