As we have 3 types of error handling methods in pure VB or VBA language, we can easily handle our errors like Try/Catch functionality. They are,
On Error Resume Next
On Error GoTo 0
On Error GoTo <LABEL>
But VBScript supports only 2. They are
On Error Resume Next
On Error GoTo 0
So here we are going to talk about these 2 handlers.
1. On Error Resume Next
This enables the vb error handler and whenever dynamic run time error occurs, it will collect the error information and continue with the next immediate statement. This won't stop the script execution when error occurs.
http://www.csidata.com/custserv/onlinehelp/vbsdocs/vbs241.htm
Also we will get negative error numbers also.
2. On Error GoTo 0
This is the default handler in VB. This will disables the handler and collects the error information and throw the error in msgbox. Mostly no one will use this.
Then, You can raise your custom error like,
On Error Resume Next
On Error GoTo 0
On Error GoTo <LABEL>
But VBScript supports only 2. They are
On Error Resume Next
On Error GoTo 0
So here we are going to talk about these 2 handlers.
1. On Error Resume Next
This enables the vb error handler and whenever dynamic run time error occurs, it will collect the error information and continue with the next immediate statement. This won't stop the script execution when error occurs.
- On Error Resume Next
- Dim a
- a = 5 / 0 'this will give run time error - Divide by zero error
- msgbox "Script not stopped."
- msgbox Err.Description
- On Error Resume Next
- Dim a
- a = 5 / 0 'this will give run time error - Divide by zero error
- If Err Then
- msgbox "Error occurs: " + Err.Number + "; " + Err.Message + "; " + Err.Description
- End If
http://www.csidata.com/custserv/onlinehelp/vbsdocs/vbs241.htm
Also we will get negative error numbers also.
2. On Error GoTo 0
This is the default handler in VB. This will disables the handler and collects the error information and throw the error in msgbox. Mostly no one will use this.
Then, You can raise your custom error like,
- On Error Resume Next
- Err.Clear 'Use this to clear previously stored error info
- Dim a
- a = 5 / 0 'this will give run time error - Divide by zero error
- If Err.Number <> 0 Then
- 'Err.Raise code, message, description
- Err.Raise 100, "Please change the value", "Division by Zero error occurs"
- End If
Comments
Post a Comment