The following is an overview of the VB error handling logic for ActiveX screen code. Including the following in your screen code will provide an orderly handling of VB errors if they should occur. In the case of an unplanned VB error the program will present a Windows message box reporting the error condition. Then the program will shut down and close the browser. Several standard lines of code are required for each screen. The IobjSafe.bas module is automatically included in your project. The ErrRpt Subroutine called by the error handler is included in this code. The following is automatically included at the start of your code. Code Block |
---|
Option Explicit
Event GoToURL(Url As String)
Event ErrorTerminate()
Implements IObjectSafety
The following sample shows the base framework for a Sub or Function
Private Sub DemoSub() As Long)
Dim liTmp AS Integer
On Error GoTo ErrorHandler <- Set the location to branch to in case of error
mbError = False <- Reset the error flag variable
‘ Start of your Code
‘ blah blah blah
‘ End of your code |
On Error GoTo 0
Turn off the error handler for this sub. This is important. If you omit this line it is possible that an error generated in some other section of the code will branch here and report the wrong failing program location. Exit Sub
Exit (Note: If you have written a Function then change to Exit Function) ErrorHandler:
The following is the general error handler. Based on the error number, the program will proceed. If your code may generate an error that is expected under normal operating conditions, then handle it here. If the error is not included in the list of Select statement Case numbers, then the code will call a general purpose reporting procedure. Select Case Err.Number
Case 9
For example if error number 9 (Subscript out of range) is generated by a bad user data entry, then you may catch it here and respond. MsgBox "The value you entered is not valid! Please check your input"
mbError = False Case Else
ErrMsg ("DemoSub")
Update this text to indicate the Sub or Function name. The string will be included in the error message reporting. You may also add any additional debug information. End Select
If mbError Then If mbError is true then the ActiveX code will call back to the browser via the ErrorTerminate event. Code Block |
---|
RaiseEvent ErrorTerminate
Else
Resume Next |
If you handled the error and would like to have the program continue, then set mbError to False. End If
End Sub
|