Why are class errors only caught at runtime?
I have a VB6 class with a method that throws an error:
Public Sub DoSomething
...
err.Raise 12345, description:="Error message"
...
End Sub
This method is called from the form:
Public Sub ErrTest()
On Error Goto err1
obj.DoSomething
Exit Sub
err1:
MsgBox err.Description
End Sub
This works fine at runtime, but at design time, error handling doesn't work. Instead, the VB6 IDE displays its standard message box from where I can enter debug mode or terminate the program.
Why is this happening? Can I prevent this?
source to share
In the VB IDE, go to the Tools tab, Option, General, Error Capture. I am assuming you have it set to "Break on All Errors", whereas you probably want "Break on Unhandled Errors".
Your statement is Err.Raise
giving a compilation error for me; try removing the curly braces.
Alternatively, you can use
Err.Raise vbObjectError + 12345, Description:="Error message"
i.e. offset your error code from the vbObjectError VB constant to make sure you don't get collisions.
source to share