Professional Documents
Culture Documents
VB Script
• Error Handling
Error Handing is the programmer’s line of defense against this
inherent unpredictability.The term error handing 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.
• Debugging
Debugging, as the name suggests, is the process of detecting,
locating, and removing bugs from a program.
Types of Errors
Before the script is run, the scripting engine parsers all of the
code,converting it into tokens.When an unrecognizable structure or
an expression is encountered, a syntax error is generated.
• You can think of logic errors as hidden errors. In general it will not
produce any kind of err msg. Instead, a logic error will produce what
programmers usually call “undesirable results”.
For ex: Sales tax calculations. Miscalculated sales tax can even
cause serious legal and financial problems.
• We can prevent some logical errors by clear cut of requirements and
design specifications, and some more logical errors can still creep
into code. Make use of “plus” operator instead of “minus” or some
other operator which is actually have to use.
• Another preventative measure against logic errors is what is known as
defensive programming. It is about checking assumptions about the
expected program flow and either
1. generating runtime errors 2. Including extra code
• Particularly complex problems in the form of procedures, functions,
classes and so on.
Error Visibility and Context
• Beyond displaying the error, you have other options as well. In fact,
if your script runs unattended, you might not want to display the
error at all since there is no one sitting there to click the OK button.
One of the most popular techniques is to log the error to a file, a
database, or the Windows Event Log, or e-mail to sys admin, or
page to the sys admin.
Generating Custom Errors
• Using Err.Raise
• When Not to Use Err.Raise
• When to Generate Custom Errors
Using Err.Raise
Not to Generate
Ex: err.raise vbObjectError+15000, “ERR_MSG_UGLY.VBS”,
“Hey, stupid, you can’t enter a zero! It will “ & “cause a divide
by zero error!”
To Generate
Ex: err.raise vbObjectError+15000,
“ERR_MSG_NICE.Dividenumbers()”, “Divison by zero not
allowed”
Debugging
What is Debugging?
Debugging