Provides ability to “raise” errors yourself. Any vbscript code you write can at any time stop execution and generate an error. The key to this ability is the raise method of the Err object
Using Err.Raise
When Not to Use Err.Raise
When to Generate Custom Errors
Using Err.Raise:
It is always available for global scope. That means you can refer to it any time you want without having to declare a variable for it.
Syntax is:
Err. Raise (number, source, description, helpfile, helpcontext)
Ex: Err. raise vbObjectError+ 10000,_ “ MyScript.myFuntion”,” the Age arg of Myfunc may not be greater than 150.”
Error number between 0 and 65535, 0 as the absence of an error.
Adding vbobjecterror to your error num makes sure your error num will not clash with “official microsoft error numbers.
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”
No comments:
Post a Comment