Chapter 6. Error Handling and Debugging

No explanation or tutorial of a programming language is complete without thorough coverage of error handling (also known as exception handling). It is of course important to learn the syntax of a language and to use correct logic in your programs. What truly gives a program or script professional polish — what separates throwaway from production quality — is error handling.

Writing a computer program, even a simple one, is a delicate matter. You have to get the syntax exactly right. You have to place the quote marks and the parentheses just so. You have to name the files in a particular way. You have to follow a certain kind of logic.

What's more, your program does not exist in a vacuum. A VBScript program can interact directly or indirectly with the scripting host, the operating system, the user, the network, and the Internet. A script is beset by the possibility of full disks, invalid user entries, scrambled file formats, and the electricity suddenly dropping out. Things can, and will, go wrong.

Error handling is the programmer's main line of defense against this inherent unpredictability. The term error handling refers not only to how a program responds when an error occurs, but also to how it prevents errors from happening in the first place.

The topic of debugging goes hand in hand with that of error handling. Debugging, as the name suggests, is the process of detecting, locating, and removing bugs from a program. The removing part of that ...

Get VBScript Programmer's Reference, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.