dance2die
dance2die

Reputation: 36905

Guess this goto label

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

Upvotes: 0

Views: 334

Answers (4)

Peter M
Peter M

Reputation: 7493

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.

Upvotes: 0

Paul Tomblin
Paul Tomblin

Reputation: 182782

"***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;

Upvotes: 4

Daniel Daranas
Daniel Daranas

Reputation: 22624

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

Upvotes: 0

Ryan Brunner
Ryan Brunner

Reputation: 14851

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

Upvotes: 13

Related Questions