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