Question

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...

Was it helpful?

Solution

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

OTHER TIPS

"***E***rror ***H***andler"

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;

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top