tags:

views:

76

answers:

9

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

+1  A: 

I've seen ErrorHandler: most often.

Pavel Minaev
+1  A: 

Just be consistent.

Austin Salonen
A: 

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.

agrothe
+2  A: 

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

Chris J
Hehehehe. I've got the odd little bits of code, mostly in Select Case modules which the user should never, ever encounter, which state "Tell Tony he's a moron." and similar.
Tony Toews
@Tony: Steve McConnell tells a story in Code Complete of a user report of the error message "You have a bad pointer, dogbreath". He says luckily that user had a sense of humour, but he resolved not to put jokes in error messages again. You have to realise the user might be trying to get work done against a tight deadline and might not see the funny side. Obviously doesn't apply to things like error labels that the user won't see.
MarkJ
On the original question - just be consistent.
MarkJ
+1  A: 

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.

Tony Toews
A: 

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

Oorang
A: 

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
Beaner
That's a bit too much work for me altough MZTools would make that real easy.
Tony Toews
A: 

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!

onedaywhen
A: 

The best naming convention is the consistent one.

Fernando