Home > Archive > Visual Basic > September 2004 > Error handling with a class module (VB6)
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Error handling with a class module (VB6)
|
|
| Shawn Ferrier 2004-09-28, 8:55 pm |
| Good afternoon, folks.
Have a newbie question that I hope someone might assist me with. Have
a basic form and class module. Code for the form is thus:
-----
Private Sub Form_Load()
Dim clsClass1 As New Class1
On Error GoTo ErrorRoutine
clsClass1.Test
' If I replace the above line with this:
' Err.Raise vbObjectError + 513, , "Some error happened here."
' the error handling works as expected.
MsgBox "How come this text gets displayed??"
Unload Me
Exit Sub
ErrorRoutine:
MsgBox "Error: " & Err.Description, vbOKOnly, "Error #" & Err.Number
Exit Sub
End Sub
-----
Code for the class module is thus:
-----
Public Sub Test()
On Error Resume Next
Err.Raise vbObjectError + 513, , "Error in class module."
End Sub
-----
Can someone explain why, when the error is raised in the class module,
the 'ErrorRoutine' handler isn't followed? That line 'MsgBox "How
come this text gets displayed"' should never be displayed??
Thanks so much,
Shawn.
sferrier at gmail dot com
| |
| Douglas Marquardt 2004-09-28, 8:55 pm |
| Hi Shawn:
Because you have set On Error Resume Next,
vb will ignore the error you raised.
Try removing the On Error Resume Next
from Test and see what happens.
Doug.
"Shawn Ferrier" <jeanchretien2@hotmail.com> wrote in message news:daf1bfeb.0409281330.1bff7db6@posting.google.com...
> Good afternoon, folks.
>
> Have a newbie question that I hope someone might assist me with. Have
> a basic form and class module. Code for the form is thus:
>
> -----
> Private Sub Form_Load()
> Dim clsClass1 As New Class1
>
> On Error GoTo ErrorRoutine
> clsClass1.Test
> ' If I replace the above line with this:
> ' Err.Raise vbObjectError + 513, , "Some error happened here."
> ' the error handling works as expected.
> MsgBox "How come this text gets displayed??"
> Unload Me
> Exit Sub
>
> ErrorRoutine:
> MsgBox "Error: " & Err.Description, vbOKOnly, "Error #" & Err.Number
> Exit Sub
> End Sub
> -----
>
> Code for the class module is thus:
> -----
> Public Sub Test()
> On Error Resume Next
> Err.Raise vbObjectError + 513, , "Error in class module."
> End Sub
> -----
>
> Can someone explain why, when the error is raised in the class module,
> the 'ErrorRoutine' handler isn't followed? That line 'MsgBox "How
> come this text gets displayed"' should never be displayed??
>
> Thanks so much,
> Shawn.
> sferrier at gmail dot com
|
|
|
|
|