GoTo ErrorJunkie / Dummy exit



  • First of all, sorry about my "bad english", second language.



    I work in a B2B company in Eastern Canada. We currently supporting some
    applications done by "Professionals programming firm" which now, have
    closed theirs doors.



    One of our client call me last week about a strange problem with his
    program : when he try to run it, the application end without any log or
    error message.



    I'm not an expert in vb since i really appreciate more php and java, but I think i found the problem.



    What I saw is probably a great "vb try/catch" created by a true professional programmer.



    Is "Dummy exit" "GoTo ErrorJunkie" supposed to give stability to this app? I dont think so...



    Sub startClients()

        'Start Mapping function

        On Error GoTo ErrorJunkie

        Dim ret As Integer

        Dim X As Long

        Dim informationsClient() As String

        

        'Show wait form

        frmExporting.Show

        'on top

        'SetWindowPos frmExporting.hWnd, -1, 0, 0, 0, 0, &H1 Or &H2

        For X = 0 To lstClientsInclus.ListCount - 1

            '0 = client number

            '1 = client na,e

            informationsClient = Split(lstClientsInclus.List(X), Chr(9))

            ret =
    InvoiceDataList(Trim(informationsClient(0)),
    getCurrentPosition(Trim(informationsClient(0))))

            If ret = 1 Then

                Exit Sub

            End If

        Next

        'open wait form show

        frmExporting.Hide

        ret = MsgBox("Mapping Done!", vbInformation + vbOKOnly, App.Title)

        Exit Sub

        

    ErrorJunkie:

        End 'Dummy exit

    End Sub




  • Looks like unfinished code, like they intended to flesh out the errortrapping routine and never got back to it.



  • I kept trying to reply, but my browser kept screwing up. I'll keep it short and sweet so I'm not wasting my time writing out my response a 3rd time just to have it fail...

    I utterly HATE when VB morons use "On Error GoTo" and "End". GoTo should never be used except in extreme circumstances. In this case, as with most cases I've seen it used, it's just so the coder doesn't have to try to account for where the error happened or what to do if something goes wrong. Oh there was a run-time error? Oh well, exit out of that sub then. NO! That's the lazy way out, and it provides no information to the user. You can usually eliminate the "On Error GoTo" by putting in some checks to verify data integrity, or try to catch errors at the point where they might occur. Of course that requires THINKING about the problem.

    As for the use of "End"... ugh. Again, the lazy way out. Completely unload everything without warning, shut down all open connections, and close all files that the program may have open. Not exactly graceful, or safe.

    In this case, the programmer mixes the two and creates something that Satan himself would cringe at. If an error of any kind happens at any point in this subroutine, completely unload the program without warning or explanation.

    And I don't care if this was development code that mysteriously made it into production software. That compounds the WTF by not having a testing and code review process. And for the record, I've developed in VB for years now, and I've never used GoTo or End, this guy is not exactly a beginner from the looks of things (Split, array structures, API calls).



  • @Manni said:

    I utterly HATE when VB morons use "On Error GoTo" and "End". GoTo should never be used except in extreme circumstances. In this case, as with most cases I've seen it used, it's just so the coder doesn't have to try to account for where the error happened or what to do if something goes wrong. Oh there was a run-time error? Oh well, exit out of that sub then......

    lol.  I know the feeling.  I used to work with a guy who had never used error handling until he read about try/catch blocks in C#.  Then he started wrapping every line of code he wrote in a try block.  The best part was that the catch blocks didn't do anything at all.  I guess he just didn't want to know about the exceptions...






Log in to reply