Handle Errors Within Forms
Handle Errors Within Forms
Rate Handle Errors Within Forms
(1(1 Vote))
When you load or show a form, errors don’t bubble up. That is, even if the calling procedure has an error handler, and an error occurs in Form_Load, Form_Initialize, or any other form event, processing doesn’t transfer to the calling error handler. In this code, Sub Main has an error handler. But when an error occurs in the Form_Load, the error handler isn’t called:
' Code in a bas module
Sub Main()
On Error Resume Next
Load Form1
' further processing code ...
End Sub
' Code in Form1
Private Sub Form_Load()
Dim a As Integer
a = 1 / 0 ' error is fatal!
End Sub
If you check the call stack when the error occurs, you see an entry '<Non-Basic Code>' before the Form_Load. Even though Sub Main is loading Form1, Sub Main is not the direct caller of Form_Load, and that results in this behavior.
'thanx to Ravindra Okade
'We bear witness that there is no God but Allah and Muhammad is the slave and prophet of Allah!
Handle Errors Within Forms Comments
No comments yet — be the first to post one!
Post a Comment