I have a VB6 class with a method which raises an error:
Public Sub DoSomething ... err.Raise 12345, description:='Error message' ... End Sub
This method is called from a 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 the error handling does not work. Instead the VB6 IDE displays its standard message box from where I can go into debug mode or end the program.
Why does this happen? Can I prevent it?
In the VB IDE, go to Tools, Option, General tab, Error trapping frame. I’m guessing you have it set to ‘Break on All Errors’, whereas you probably want ‘Break on Unhandled Errors’.
Your
Err.Raisestatement gives a compile error for me; try removing the braces.Also, you may want to use
i.e. offset your error code from the VB constant vbObjectError to be sure you don’t get clashes.