Chapter 9: Exception Handling and Debugging


Overview

All professional-grade programs need to handle unexpected conditions. In programming languages before Microsoft .NET, this was often called error handling. Unexpected conditions generated 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 communicate various items of useful information about what went wrong.

Because .NET deals with exceptions instead of errors, the term “error handling” is seldom 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 2005. There are many improvements over pre-.NET versions of Visual Basic. This chapter discusses the common language runtime (CLR) exception handler in detail and the programming methods that are most efficient in catching errors. Specifically, this chapter covers the following:

  • A brief review of error handling in Visual Basic 6 (VB6)

  • The general principles behind exception handling

  • The Try...Catch...Finally structure, the Exit Try statement, and nested Try structures

  • The exception object’s methods and properties

  • Capabilities in Visual Studio .NET to work with exceptions

  • Error and trace logging and how you can use these methods to obtain feedback on how your program is working

You’ll begin with a quick review of error handling in previous versions of Visual Basic to use as a reference point. Then you will learn new ways to handle exceptions in .NET.




Professional VB 2005 with. NET 3. 0
Professional VB 2005 with .NET 3.0 (Programmer to Programmer)
ISBN: 0470124709
EAN: 2147483647
Year: 2004
Pages: 267

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net