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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Continue program after encountering error

Continue program after encountering error

Scheduled Pinned Locked Moved C#
helpquestionjson
8 Posts 5 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 Offline
    M Offline
    Member 14474607
    wrote on last edited by
    #1

    Hello - I had records to be processed at a time, and the 4th record had an issue. The entire program failed, not processing the rest of the records which had no issue. How can I can continue the program processing the good records? Thanks!!

    D N L OriginalGriffO 4 Replies Last reply
    0
    • M Member 14474607

      Hello - I had records to be processed at a time, and the 4th record had an issue. The entire program failed, not processing the rest of the records which had no issue. How can I can continue the program processing the good records? Thanks!!

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

      You apparently don't know about try/catch blocks? How to: Use the Try-Catch Block to Catch Exceptions | Microsoft Docs[^]

      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
      Dave Kreskowiak

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        You apparently don't know about try/catch blocks? How to: Use the Try-Catch Block to Catch Exceptions | Microsoft Docs[^]

        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
        Dave Kreskowiak

        M Offline
        M Offline
        Member 14474607
        wrote on last edited by
        #3

        I have a catch block in the code which catches all exceptions and writes to log file. How can I make it that the program continues processing the good records instead of not processing the entire batch.

        D 1 Reply Last reply
        0
        • M Member 14474607

          Hello - I had records to be processed at a time, and the 4th record had an issue. The entire program failed, not processing the rest of the records which had no issue. How can I can continue the program processing the good records? Thanks!!

          N Offline
          N Offline
          NotTodayYo
          wrote on last edited by
          #4

          There is no specific way to answer you because we have no idea how you are processing the records. One way to do it is to process one record at a time and put that code in a try catch, inside the loop. That way the loop will continue. However, if the problem is that the database is not available, for example, then it's going to throw an exception for every single record you are processing.

          1 Reply Last reply
          0
          • M Member 14474607

            I have a catch block in the code which catches all exceptions and writes to log file. How can I make it that the program continues processing the good records instead of not processing the entire batch.

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

            You haven't supplied any relevant code so it's impossible to tell you with any accuracy. But, the try/catch block should surround only the processing of a single record, NOT THE ENTIRE LIST OF THEM.

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
            Dave Kreskowiak

            L 1 Reply Last reply
            0
            • M Member 14474607

              Hello - I had records to be processed at a time, and the 4th record had an issue. The entire program failed, not processing the rest of the records which had no issue. How can I can continue the program processing the good records? Thanks!!

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

              Ask what you want the try-catch to do; retry the current item, or skip it and progress to the next. Retrying should be limited.

              Bastard Programmer from Hell :suss: "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

              1 Reply Last reply
              0
              • M Member 14474607

                Hello - I had records to be processed at a time, and the 4th record had an issue. The entire program failed, not processing the rest of the records which had no issue. How can I can continue the program processing the good records? Thanks!!

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

                To add to what the others have said, you might also want to look at why the record failed - what did it contain that you didn't expect? Was it something you should have expected, or been able to handle? For example, if a user is to enter a page full of information and a single item is wrong, you shouldn't invalidate the whole page - just get the user to enter the right value. We can't see your screen, access your HDD, or read your mind - so we have no idea what your code is doing, or how it is doing it; but graceful error handling is an important part of any app!

                "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 AntiTwitter: @DalekDave is now a follower!

                "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

                1 Reply Last reply
                0
                • D Dave Kreskowiak

                  You haven't supplied any relevant code so it's impossible to tell you with any accuracy. But, the try/catch block should surround only the processing of a single record, NOT THE ENTIRE LIST OF THEM.

                  Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                  Dave Kreskowiak

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

                  That sums it up.

                  It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                  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