|
Free Open Book
Windows XP Annoyances |
9.12 Deciphering Script ErrorsOne of the general disadvantages of scripts is that they are typically created with a plain-text editor, rather than a rich debugging environment used with many more sophisticated programming languages (see Section 9.13 later in this chapter). Because Notepad isn't specifically designed to understand VBScript, it can't offer any assistance with syntax (grammar) or errors while you're editing. Therefore, you must wait until you run the script to see if there are any problems. If WSH encounters an error, it will display a message similar to that shown in Figure 9-2. Figure 9-2. The Windows Script Host displays a message like this whenever it encounters an error.
Surprisingly, this sparse message box actually provides enough information to resolve most problems. Naturally, the first field, Script, shows the script filename in which the error occurred. This is especially useful if the script was run from a scheduled task or from your Startup folder, and you might otherwise not know which script caused the error. The Line Number and Column fields show exactly where in the script the error occurred, and include blank lines and remarks. If you're using Notepad, select Status Bar from the View menu to display the line number at which the insertion point (text cursor) is resting. Or, select Go To from Notepad's Edit menu to quickly jump to any line. Better yet, switch to a better text editor (discussed later in this chapter) that has more debugging tools, such as numbered lines. The Category field describes—more than anything else—what it was doing when it encountered the error. A compilation error occurs when WSH is first reading the file and making sure all of the commands are correctly entered; you'll see this if you forgot a parenthesis or quotation mark, misspelled a command, or left out some other important keyword. A runtime error , on the other hand, is an error encountered while the script was being executed; this is caused by errors that WSH doesn't know are errors until it actually tries them, such as trying to read from a file that doesn't exist or trying to calculate the square root of a negative number. Lastly, the Description field shows a brief explanation of the error encountered. Sometimes it's helpful, but most of the time it's either too vague or too cryptic to be of much help. This is where programming experience comes in handy for interpreting these messages and figuring out what caused them. The following are a few of the more common error descriptions and what they mean:
If you plan on distributing your scripts, you'll want to take steps to eliminate any error messages that may pop up. See the Section 9.4 example script earlier in this chapter for more information on error trapping and the On Error Resume Next statement. |
Main Menu |
| 500 Juegos Gratis | 500 Giochi Gratis | 500 Jeux Gratuits | 500 Jogos Gratis | 500 Kostenlose Spiele |