Tutorial :Error handler naming [closed]



Question:

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


Solution:1

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 :-)


Solution:2

I've seen ErrorHandler: most often.


Solution:3

Just be consistent.


Solution:4

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.


Solution:5

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.


Solution:6

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


Solution:7

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

example:

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  


Solution:8

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

Err_Handler  

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


Solution:9

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
Previous
Next Post »