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

    M Offline
    M Offline
    Mike Dimmick
    wrote on last edited by
    #8

    Phannon wrote:

    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.

    Stupid ivory-tower taboos. A goto statement can be helpful. But you should never use it where a structured control statement would be more appropriate. For some interesting reading see Gotos Considered Harmful and Other Programmers' Taboos[^].

    DoEvents: Generating unexpected recursion since 1991

    C B 2 Replies Last reply
    0
    • P peterchen

      After all, it could also have been ON ERROR RESUME NEXT

      We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
      blog: TDD - the Aha! | Linkify!| FoldWithUs! | sighist

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

      :) very true. I shall be thankful for small mercies.

      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

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

        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 J A 3 Replies Last reply
        0
        • M Mike Dimmick

          Phannon wrote:

          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.

          Stupid ivory-tower taboos. A goto statement can be helpful. But you should never use it where a structured control statement would be more appropriate. For some interesting reading see Gotos Considered Harmful and Other Programmers' Taboos[^].

          DoEvents: Generating unexpected recursion since 1991

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #11

          I fully agree with you. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

          1 Reply Last reply
          0
          • M Mike Dimmick

            Phannon wrote:

            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.

            Stupid ivory-tower taboos. A goto statement can be helpful. But you should never use it where a structured control statement would be more appropriate. For some interesting reading see Gotos Considered Harmful and Other Programmers' Taboos[^].

            DoEvents: Generating unexpected recursion since 1991

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

            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.

            D B 2 Replies Last reply
            0
            • P Paddy Boyd

              You know it's not going to be a good morning when you open up a legacy VB.net project and find hundreds of functions littered with ON ERROR GOTO's...

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

              Paddy Boyd wrote:

              Stupid ivory-tower taboos.

              I almost worked on a POS, also littered with those, but with the added qualifications, such as If Err.Number = nnn Then Resume Next Trying to find an error causing line was hell, because with Break on All Errors turned on, nearly every line caused an error, which was handled by code such as the above. Things like invalid array indexes, empty strings etc. that could all have been ignored with a proper code check, such as If i > UpperBound Then DoNothing, but no, it was just Write strData(i) and let the f****ing error handler see if the error was important.

              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.

                D Offline
                D Offline
                David Stone
                wrote on last edited by
                #14

                Agreed! On Error Resume Next, to me, always seems like saying "Eh. Who cares about what we're doing. The user should notice that half their data failed to get through our routine and fix it themselves..."

                1 Reply Last reply
                0
                • P Paddy Boyd

                  You know it's not going to be a good morning when you open up a legacy VB.net project and find hundreds of functions littered with ON ERROR GOTO's...

                  M Offline
                  M Offline
                  Mike Dimmick
                  wrote on last edited by
                  #15

                  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 B 2 Replies 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

                    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