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?

0


source to share


2 answers


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.

+5


source


You can also change the error capture options by right clicking in the code window. The following options are available in the "Toggle" submenu:

Break in all errors
Break in class module
Break on unhandled errors



I find this much easier than the Options pop-up dialog ...

+1


source







All Articles