I'm used to programing in C#, which obviously has some pretty robust error handling. Now I'm working on a short project in VBScript. I've read about the error handling with VBscript using "On Error _______" and the Err
global variable.
However, is there some way I can generate my own errors? For example if one of my functions is passed the wrong type of parameter I'd rather my script just flat out fail at that point then try to continue.
Q 42 - Which of the following is used to clear error in VBScript? A - Err.
The Err object is part of the VBScript language and contains information about the last error to occur. By checking the properties of the Err object after a particular piece of code has executed, you can determine whether an error has occurred and, if so, which one.
VB.NET Masterclass: Learn Visual Basic and VBScript There are three types of errors in programming: (a) Syntax Errors, (b) Runtime Errors, and (c) Logical Errors.
The Err object is an intrinsic object with global scope — there is no need to create an instance of it in your code. The properties of the Err object are set by the generator of an error — Visual Basic, an Automation object, or the VBScript programmer. The default property of the Err object is Number. Err.
Yes, you can. Use the Err.Raise
method, e.g.:
Err.Raise 5 ' Invalid procedure call or argument
For a list of VBScript's standard error codes, see Errors (VBScript).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With