Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. On error goto....

On error goto....

Scheduled Pinned Locked Moved The Lounge
csharphelp
27 Posts 15 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Mike Dimmick

    It's the only way of handling exceptions in VB6. VB6 also wouldn't give you a call stack so you basically had to do it yourself by putting On Error Goto in every function. Now, if it was ported to VB.NET and not translated to Try/Catch, then you have my sympathy. If it was written new in VB.NET, not a translation from VB6, then the programmer should be shotretrained.

    DoEvents: Generating unexpected recursion since 1991

    P Offline
    P Offline
    Paddy Boyd
    wrote on last edited by
    #16

    I know. And i believe, written from scratch...

    1 Reply Last reply
    0
    • P phannon86

      Bleh, goto X| At uni we had the true evil of the statement hammered into us on a C++ course, for every goto in our assignments you will lose 50% of the marks. :laugh:

      He who makes a beast out of himself gets rid of the pain of being a man

      N Offline
      N Offline
      NormDroid
      wrote on last edited by
      #17

      You'll find goto used in Microsoft code especially in cleanup functions.

      There is no Ctrl button on Chuck Norris's computer. Chuck Norris is always in control

      1 Reply Last reply
      0
      • V V 0

        use goto, continue or break, you fail (break only allowed in switch statements.) use more then one exit in your function, you fail. and the prof was right... :)

        V.
        Stop smoking so you can: Enjoy longer the money you save. Moviereview Archive

        B Offline
        B Offline
        Brady Kelly
        wrote on last edited by
        #18

        I often use continue. It greatly improves readability.

        1 Reply Last reply
        0
        • M Mike Dimmick

          It's the only way of handling exceptions in VB6. VB6 also wouldn't give you a call stack so you basically had to do it yourself by putting On Error Goto in every function. Now, if it was ported to VB.NET and not translated to Try/Catch, then you have my sympathy. If it was written new in VB.NET, not a translation from VB6, then the programmer should be shotretrained.

          DoEvents: Generating unexpected recursion since 1991

          B Offline
          B Offline
          Brady Kelly
          wrote on last edited by
          #19

          Mike Dimmick wrote:

          Now, if it was ported to VB.NET and not translated to Try/Catch, then you have my sympathy.

          Or if it was, but with every (now) method being neatly wrapped up in a 'try' 'catch (Exception ex)' 'throw new Exception("Error!", ex);'

          1 Reply Last reply
          0
          • B Brady Kelly

            Mike Dimmick wrote:

            Stupid ivory-tower taboos.

            Yes, I agree, but On Error Resume Next should be punished by stoning to death with golf balls.

            B Offline
            B Offline
            BadKarma
            wrote on last edited by
            #20

            Brady Kelly wrote:

            Yes, I agree, but On Error Resume Next should be punished by stoning to death with golf balls.

            True, but that should also apply to the try/catch/do-nothings.

            codito ergo sum

            B 1 Reply Last reply
            0
            • B BadKarma

              Brady Kelly wrote:

              Yes, I agree, but On Error Resume Next should be punished by stoning to death with golf balls.

              True, but that should also apply to the try/catch/do-nothings.

              codito ergo sum

              B Offline
              B Offline
              Brady Kelly
              wrote on last edited by
              #21

              Yes, even the try/catch/do-nothing-but-throw-again-and-break-the-call-stack.

              A 1 Reply Last reply
              0
              • V V 0

                use goto, continue or break, you fail (break only allowed in switch statements.) use more then one exit in your function, you fail. and the prof was right... :)

                V.
                Stop smoking so you can: Enjoy longer the money you save. Moviereview Archive

                J Offline
                J Offline
                JudyL_MD
                wrote on last edited by
                #22

                Multiple exits can greatly improve readability when you have extensive error checking at the start of the routine. Judy

                D 1 Reply Last reply
                0
                • B Brady Kelly

                  Yes, even the try/catch/do-nothing-but-throw-again-and-break-the-call-stack.

                  A Offline
                  A Offline
                  Andy Brummer
                  wrote on last edited by
                  #23

                  I've seen way way too many of those in the short time that I've been working in C#. It's too late now, but it should have been the first thing taught to every VB developer making the transition. Even before they learned the syntax.

                  This blanket smells like ham

                  1 Reply Last reply
                  0
                  • V V 0

                    use goto, continue or break, you fail (break only allowed in switch statements.) use more then one exit in your function, you fail. and the prof was right... :)

                    V.
                    Stop smoking so you can: Enjoy longer the money you save. Moviereview Archive

                    A Offline
                    A Offline
                    Andy Brummer
                    wrote on last edited by
                    #24

                    I use continue all the time, and if you have a function that doesn't support multiple return statements easily then your function is probably too complicated. Though, back in the C days it was hard to keep functions simple enough. My arbitrary flow control dogma would be if you have more then 2 nested if, while, switch or for statements you fail.

                    This blanket smells like ham

                    V 1 Reply Last reply
                    0
                    • A Andy Brummer

                      I use continue all the time, and if you have a function that doesn't support multiple return statements easily then your function is probably too complicated. Though, back in the C days it was hard to keep functions simple enough. My arbitrary flow control dogma would be if you have more then 2 nested if, while, switch or for statements you fail.

                      This blanket smells like ham

                      V Offline
                      V Offline
                      V 0
                      wrote on last edited by
                      #25

                      Andy Brummer wrote:

                      if you have a function that doesn't support multiple return statements easily then your function is probably too complicated

                      On the contrary, bugfixing with your function only having one return is more easy than when it has, let's say, 5 return statements. There's nothing more ugly then having something like this

                      if(something == true){
                      return;
                      }

                      tastes differ I guess :-)

                      V.
                      Stop smoking so you can: Enjoy longer the money you save. Moviereview Archive

                      1 Reply Last reply
                      0
                      • J JudyL_MD

                        Multiple exits can greatly improve readability when you have extensive error checking at the start of the routine. Judy

                        D Offline
                        D Offline
                        Dan Neely
                        wrote on last edited by
                        #26

                        With extensive (more than 2 or 3 checks) I generally refactor all the error checking into bool ValidateFunctionName(...).

                        Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop. -- Matthew Faithfull

                        J 1 Reply Last reply
                        0
                        • D Dan Neely

                          With extensive (more than 2 or 3 checks) I generally refactor all the error checking into bool ValidateFunctionName(...).

                          Otherwise [Microsoft is] toast in the long term no matter how much money they've got. They would be already if the Linux community didn't have it's head so firmly up it's own command line buffer that it looks like taking 15 years to find the desktop. -- Matthew Faithfull

                          J Offline
                          J Offline
                          JudyL_MD
                          wrote on last edited by
                          #27

                          True, but that Validate function is still easiest to read if it has multiple return false statements for each error check that fails and one final return true at the end if it passes all the tests. Regardless of where the error checking is, I always find it more readable to do it this way rather than massively nesting the multiple error checking to force the routine into only having a single exit point - the OP's original point. Judy

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups