Can I throw an error in vbscript?

Eric Anastas picture Eric Anastas · Dec 21, 2010 · Viewed 33.3k times · Source

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.

Answer

Helen picture Helen · Dec 21, 2010

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).