Error Handler - Exit Sub vs. End Sub

error-handling, vb6, vba

Solution

Your ProcExit label is your place where you release all the resources whether an error happened or not. For instance:

Public Sub SubA()
  On Error Goto ProcError

  Connection.Open
  Open File for Writing
  SomePreciousResource.GrabIt

ProcExit:  
  Connection.Close
  Connection = Nothing
  Close File
  SomePreciousResource.Release

  Exit Sub

ProcError:  
  MsgBox Err.Description  
  Resume ProcExit
End Sub

Problem

Why would I want to get out of an Error Handler (after handling) with an Exit Sub instead of just letting it go to the End Sub? I'm sure it's simple. I just don't understand. Thanks for any help. Example: ``` Public Sub SubA() On Error Goto ProcError ''# other code MsgBox FuncA() ProcExit: Exit Sub ProcError: MsgBox Err.Description Resume ProcExit End Sub ```

Original source