Section 12.2. Exception Handling Overview


12.2. Exception Handling Overview

Programs frequently test conditions to determine how program execution should proceed. Consider the following pseudocode:


Perform a task
If the preceding task did not execute correctly
     Perform error process ing
Perform next task
If the preceding task did not execute correctly
     Perform error processing
...

In this pseudocode, we begin by performing a task; then we test whether that task executed correctly. If not, we perform error processing. Otherwise, we continue with the next task. Although this form of error handling works, intermixing program logic with error-handling logic can make programs difficult to read, modify, maintain and debugespecially in large applications.

Exception handling enables you to remove error-handling code from the "main line" of the program's execution, improving program clarity and enhancing modifiability. You can decide to handle any exceptions you chooseall exceptions, all exceptions of a certain type or all exceptions of a group of related types (i.e., exception types that are related through an inheritance hierarchy). Such flexibility reduces the likelihood that errors will be overlooked, thus making programs more robust.

With programming languages that do not support exception handling, programmers often delay writing error-processing code and sometimes forget to include it. This results in less robust software products. Visual Basic enables you to deal with exception handling easily from the beginning of a project.



Visual BasicR 2005 for Programmers. DeitelR Developer Series
Visual Basic 2005 for Programmers (2nd Edition)
ISBN: 013225140X
EAN: 2147483647
Year: 2004
Pages: 435

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