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. General Programming
  3. C#
  4. On Error Resume Next

On Error Resume Next

Scheduled Pinned Locked Moved C#
csharphelpquestioncareer
13 Posts 10 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hello Everybody, As you know In vb.net or vb6 the On Error Resume Next is use to error handling in a function or procedure. In C# have any one for handling error? Best Regard

    If you can think then I Can.

    J D A OriginalGriffO _ 6 Replies Last reply
    0
    • L Lost User

      Hello Everybody, As you know In vb.net or vb6 the On Error Resume Next is use to error handling in a function or procedure. In C# have any one for handling error? Best Regard

      If you can think then I Can.

      J Offline
      J Offline
      JF2015
      wrote on last edited by
      #2

      Hi, I would really not recommend you to use "On Error Resume Next", but if you really need it though you can see this article for a solution: http://www.dotnetfunda.com/articles/article168.aspx[^] A very basic implementation in C# that does the same would be:

      try { foo; } catch {}

      L F 2 Replies Last reply
      0
      • L Lost User

        Hello Everybody, As you know In vb.net or vb6 the On Error Resume Next is use to error handling in a function or procedure. In C# have any one for handling error? Best Regard

        If you can think then I Can.

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        eg_Anubhava wrote:

        As you know In vb.net or vb6 the On Error Resume Next is use to error handling

        In VB6, that was the case. It's still usable in VB.NET, but not recommended at all. Use Try/Catch blocks in VB.NET and C#. BTW: C# doesn't have an alternative to this.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak

        1 Reply Last reply
        0
        • J JF2015

          Hi, I would really not recommend you to use "On Error Resume Next", but if you really need it though you can see this article for a solution: http://www.dotnetfunda.com/articles/article168.aspx[^] A very basic implementation in C# that does the same would be:

          try { foo; } catch {}

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          thanks sir

          If you can think then I Can.

          1 Reply Last reply
          0
          • L Lost User

            Hello Everybody, As you know In vb.net or vb6 the On Error Resume Next is use to error handling in a function or procedure. In C# have any one for handling error? Best Regard

            If you can think then I Can.

            A Offline
            A Offline
            Abhinav S
            wrote on last edited by
            #5

            This[^] might help you.

            The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick

            1 Reply Last reply
            0
            • L Lost User

              Hello Everybody, As you know In vb.net or vb6 the On Error Resume Next is use to error handling in a function or procedure. In C# have any one for handling error? Best Regard

              If you can think then I Can.

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              On Error Resume Next was an abortion of a solution, used to help complete idiots make an even bigger mess of things than they had started with. What it does is hide errors. Not fix them, not get rid of them, just hide them. Until they become so huge they corrupt your data, or loose hours of user work. Imagine if you will: as simple index error:

              string[] veryValuableDataFromUsers = new string[10];
              veryValuableDataFromUsers [10] = myUserTextBox.Text;
              foreach (string data in veryValuableDataFromUsers)
              {
              SaveMyData(data);
              }

              Now, if you run this as is, an exception will be thrown when you try to access array element 10: because the array elements run from 0 to 9 inclusive. You are told what the problem is, you can can fix it in testing, all is fine. If you had On Error Resume Next, what happens? No error. the bad index is ignored, no problem occurs. Until the user tries to find his data, anyway. At which point there are two problems: 1) Very annoyed user, with possibly crucial and not recoverable information lost. 2) Bug to fix, with no idea at all of how the data came to be lost. You may even blame the idiot user for "not saving it" in the first place. 100,000 lines of code to find the problem in. Don't do it. Exceptions are there to tell you there is a problem, and let you deal with it. Don't use empty catch blocks. Log exceptions in production if you can't deal with them - that way you at least have a record of what happened when you come to fix it. But do try to handle errors correctly before they become a major problem.

              Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              N 1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                On Error Resume Next was an abortion of a solution, used to help complete idiots make an even bigger mess of things than they had started with. What it does is hide errors. Not fix them, not get rid of them, just hide them. Until they become so huge they corrupt your data, or loose hours of user work. Imagine if you will: as simple index error:

                string[] veryValuableDataFromUsers = new string[10];
                veryValuableDataFromUsers [10] = myUserTextBox.Text;
                foreach (string data in veryValuableDataFromUsers)
                {
                SaveMyData(data);
                }

                Now, if you run this as is, an exception will be thrown when you try to access array element 10: because the array elements run from 0 to 9 inclusive. You are told what the problem is, you can can fix it in testing, all is fine. If you had On Error Resume Next, what happens? No error. the bad index is ignored, no problem occurs. Until the user tries to find his data, anyway. At which point there are two problems: 1) Very annoyed user, with possibly crucial and not recoverable information lost. 2) Bug to fix, with no idea at all of how the data came to be lost. You may even blame the idiot user for "not saving it" in the first place. 100,000 lines of code to find the problem in. Don't do it. Exceptions are there to tell you there is a problem, and let you deal with it. Don't use empty catch blocks. Log exceptions in production if you can't deal with them - that way you at least have a record of what happened when you come to fix it. But do try to handle errors correctly before they become a major problem.

                Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                N Offline
                N Offline
                nlarson11
                wrote on last edited by
                #7

                Well us "idiots" had to use on error resume next when writing vb6 (and before) and vbscript in asp as it was our only means of catching an error due to object creation issues, etc. While it certainly opens itself up to what your refer to...if you never were "forced" to use it even in its intented purpose... not sure "idiots" apply in all cases.

                'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous

                OriginalGriffO M 2 Replies Last reply
                0
                • N nlarson11

                  Well us "idiots" had to use on error resume next when writing vb6 (and before) and vbscript in asp as it was our only means of catching an error due to object creation issues, etc. While it certainly opens itself up to what your refer to...if you never were "forced" to use it even in its intented purpose... not sure "idiots" apply in all cases.

                  'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #8

                  No you are right, "idiots" was a little over the top. :-D The idiots were the designers who thought it would be a good idea in the first place! I had no problem with On Error Goto, it was the inclusion of resume next as a specific way to ignore any problem which did occur which got my back up. Having been raised with FORTRAN compilers which had a default On Error Resume Next in that they did no error checking whatsoever (and would allow you to declare a character variable and use it as a four dimensional array of floats) I saw what damage a lack of error checking can do. It was a retrograde step to allow novices in particular to easily disable error checking with a single line of code.

                  Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  N 1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    No you are right, "idiots" was a little over the top. :-D The idiots were the designers who thought it would be a good idea in the first place! I had no problem with On Error Goto, it was the inclusion of resume next as a specific way to ignore any problem which did occur which got my back up. Having been raised with FORTRAN compilers which had a default On Error Resume Next in that they did no error checking whatsoever (and would allow you to declare a character variable and use it as a four dimensional array of floats) I saw what damage a lack of error checking can do. It was a retrograde step to allow novices in particular to easily disable error checking with a single line of code.

                    Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

                    N Offline
                    N Offline
                    nlarson11
                    wrote on last edited by
                    #9

                    No problem. ;P

                    'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous 'Life's real failure is when you do not realize how close you were to success when you gave up.' ~ anonymous

                    1 Reply Last reply
                    0
                    • L Lost User

                      Hello Everybody, As you know In vb.net or vb6 the On Error Resume Next is use to error handling in a function or procedure. In C# have any one for handling error? Best Regard

                      If you can think then I Can.

                      _ Offline
                      _ Offline
                      _Erik_
                      wrote on last edited by
                      #10

                      eg_Anubhava wrote:

                      As you know In vb.net or vb6 the On Error Resume Next is use to error handling

                      Just a tip: that was not "error handling"; that was "error swallowing". Error handling was achieved with "On Error Goto"

                      1 Reply Last reply
                      0
                      • J JF2015

                        Hi, I would really not recommend you to use "On Error Resume Next", but if you really need it though you can see this article for a solution: http://www.dotnetfunda.com/articles/article168.aspx[^] A very basic implementation in C# that does the same would be:

                        try { foo; } catch {}

                        F Offline
                        F Offline
                        fjdiewornncalwe
                        wrote on last edited by
                        #11

                        Such a good answer because of the question, but such a bad answer because I hate to see empty try-catches... I'm now in an argument with myself on whether to vote up or down... :)

                        I wasn't, now I am, then I won't be anymore.

                        1 Reply Last reply
                        0
                        • L Lost User

                          Hello Everybody, As you know In vb.net or vb6 the On Error Resume Next is use to error handling in a function or procedure. In C# have any one for handling error? Best Regard

                          If you can think then I Can.

                          D Offline
                          D Offline
                          Dave Doknjas
                          wrote on last edited by
                          #12

                          If you can narrow down the affected code to a line or two, then the following VB code:

                          On Error Resume Next
                          Foo()

                          can be converted to:

                          try
                          {
                          Foo();
                          }
                          catch
                          {
                          //ignore exceptions
                          }

                          For longer code blocks, you'll have to use a separate try/empty catch for each single line of code.

                          David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com

                          modified on Tuesday, January 18, 2011 4:42 PM

                          1 Reply Last reply
                          0
                          • N nlarson11

                            Well us "idiots" had to use on error resume next when writing vb6 (and before) and vbscript in asp as it was our only means of catching an error due to object creation issues, etc. While it certainly opens itself up to what your refer to...if you never were "forced" to use it even in its intented purpose... not sure "idiots" apply in all cases.

                            'Never argue with an idiot; they'll drag you down to their level and beat you with experience.' ~ anonymous

                            M Offline
                            M Offline
                            Matty22
                            wrote on last edited by
                            #13

                            Couldn't you have used on error goto instead?

                            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