VB6 exception handling in call procedure

I have two procedures procA and procB. procA calls procB. An exception occurs in procB. I can handle the exception in procB, but I like to handle it in procA, and this is what I could not work. I am not very familiar with VB6, but I think it should be possible because MSDN says:

If an error occurs when an error handler is active (between the occurrence of the error and the Resume, Exit Sub, Exit Function, or Exit Property operation), the current procedure error handler cannot handle this error. Control returns to the calling procedure. If the calling procedure has a valid error handler, it is activated to handle the error.

What am I doing wrong?

Now snippets of code:

Private Sub procA()
  On Error GoTo ErrHnd
  ...
  procB obj
  Exit Sub
ErrHnd:
  MsgBox Err.Description, vbInformation, Me.caption
End Sub

Public Sub procB(ByRef rec As Object)
  On Error GoTo ErrHnd
  ... Exception occurs within DAO Recordset Operation
  Exit Sub
ErrHnd:
  Select Case Err.Number
  Case 3022
    Err.Raise vbObjectError + 9999, Err.Source, "Error Text"
  Case Else
    ...
  End Select
End Sub

procB (On Error Goto 0), , procA Exception.

.

: :

  • DAO.Recordset.
  • procB .
  • procA , procB (data.cls, frmListArtikel.frm).

: , , . IDE, Exception procA. EXE ( IDE) , Exception procA.

+3
2

. procb, procb.

. "" > "" > "" ) " "

1. 6 procA:

Private Sub Form_Load()
    Call procA
End Sub

Private Sub procA()
    On Error GoTo errhan
    procB
    Exit Sub
errhan:
    Debug.Print "proca handle"
End Sub

Private Sub procB()
    Err.Raise 6
End Sub

2. 7 procA:

Private Sub Form_Load()
    Call procA
End Sub

Private Sub procA()
    On Error GoTo errhan
    procB
    Exit Sub
errhan:
    Debug.Print "proca handle"
End Sub

Private Sub procB()
    On Error GoTo errhan
    Err.Raise 6
errhan:
    Err.Raise 7
End Sub
+4

Source: https://habr.com/ru/post/1757671/


All Articles