Tutorial :Error handler naming [closed]


Is there a best practice for naming the error handling section? How about the resume label? I use "ErrorHandler:" and "ProcExit:". Thanks.


Not really - apart from making sure it's reasonable. If I'm using On Error Resume Next however I usually indent the code after it, e.g.:

On Error Reume Next     ' Do something at might cause an error     If Err.Number <> 0 Then        ' Do something to recover from error     End If  On Error Goto 0 'or Goto errorhandler to restore that.  

This gives a clear visual clue that you've temporarily disabled the normal error handling for a short period.

For the error handler label, I've used various including the dull 'ErrorHandler' and the rather more prosaic label 'OopsSorryIveCockedItUpAgain'. Both are fairly meaningful though :-)


I've seen ErrorHandler: most often.


Just be consistent.


I use tagError: but as others have said be consistant. I would also think that this is the only tag I use in about 99% of my code so it's not really that important.

I do very much like using MZTools to insert my standard error handling code into new functions and subroutines with the press of an icon. For VBA and VB6 it's free.


I think what matters most is that your consistent. That will make your code more readable by others and even yourself. Not to mention more maintainable etc.


I think as long as the label is clear it's fine. Personally I use ErrHnd:


Only because I can't resist adding my own preference, I prefer to name my error handlers errProcedureName.


Public Function RecordCount(ByVal AddendumFile As String) As Long  Dim fHndl As Integer  Dim nLineCount As Long  Dim strRec As String  'single line from file    On Error GoTo errRecordCount  


Many years ago, I researched common naming conventions in VB6 for labels generally (case, separators, etc) and error handlers specifically and settled on


Sorry, I can give no citation for this: too many years have passed and my links are broken!


The best naming convention is the consistent one.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »