Throw an error in vbscript

error handlingvbscript

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.

Best Answer

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