views:

216

answers:

4

I was about to refactor this following VB6 code (written by someone else).

Public Function GetValue(ID As Long) As Boolean
 On Error GoTo eh

 '' ... DAL Logic...

eh_Exit:
  On Error GoTo 0
  Exit Function
eh:
  Resume eh_Exit
End Function

What do you think the original author's intention was for the label eh?

Probably Just "eh, something happened?"...

I want to make it readable without me having to think about it just like now...

+13  A: 

Error Handler? Don't know why there's not any, you know, error handling in there.

Ryan Brunner
Beat me by 10 seconds.
Paul Tomblin
@Ryan: I think you are right...After looking at the code for a long time, I didn't think about "Error Handler"...Thanks.@Paul: +1 for guessing ;)
Sung Meister
+4  A: 

"Error Handler"

My first C job, every function had a label down near the bottom called "err_exit". Any error condition that couldn't be handled locally was detected and handled with an "if (error...) goto err_exit;". Also all our functions returned either 0 on good status, or -1 on error.

In theory, err_exit was there to do some clean up, but in practice most of our functions ended like

  return 0;
err_exit:
  return -1;
Paul Tomblin
Joel, I don't know why you capitalized my "error handler" since the label is "eh" not "EH"?
Paul Tomblin
@Joel: Ah, Joel.. nice touch.
Sung Meister
A: 

"Interesting" design. It looks like a place to put a breakpoint during debugging, but it's creatively confusing.

Daniel Daranas
After looking at the screen for too long, such acronyms seem to be getting on my nerves and I have to *think* to figure out what that means.. So i am going to change them all to "ErrorHandler_"...
Sung Meister
@dance2die, you could refactor the function a bit, too.
Daniel Daranas
@Daniel: I am on it.
Sung Meister
A: 

I would hazard a guess that it is a pattern that allows the code of the function to just end and not have to skip over any error handling logic, but also to terminate gracefully if the function writer didn't have an Exit Function statement.

Thus you can just paste everything from eh_Exit into any function without having to change the remaining code in that function.

Peter M