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. Database & SysAdmin
  3. Database
  4. On error resume next

On error resume next

Scheduled Pinned Locked Moved Database
helpdatabasetutorialquestioncareer
8 Posts 2 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.
  • V Offline
    V Offline
    vanikanc
    wrote on last edited by
    #1

    If we are selecting a set of data, and one of the fields is erroring out, with an arithematic over flow error, how to move this row aside and continue processing the remaining rows so that the entire stored procedure does not fail? More like move this row causing the issue into a table and continue processing remaining rows? Is there like on error resume next? I tried a try catch block. With in my try I had a select statement with a good value and one with a bad value, I wanted the select to print the good and not the bad one. ====================== declare @dummy int begin try select --right('00000000' + cast(cast(round(500000,0)*10000 as int) as varchar(8)),8) right('00000000' + cast(cast(round(500000,0)*10000 as int) as varchar(8)),8) select --right('00000000' + cast(cast(round(500000,0)*10000 as int) as varchar(8)),8) right('00000000' + cast(cast(round(500000,0)*10000 as int) as varchar(8)),8) end try begin catch set @dummy = 1 end catch print @dummy

    L 1 Reply Last reply
    0
    • V vanikanc

      If we are selecting a set of data, and one of the fields is erroring out, with an arithematic over flow error, how to move this row aside and continue processing the remaining rows so that the entire stored procedure does not fail? More like move this row causing the issue into a table and continue processing remaining rows? Is there like on error resume next? I tried a try catch block. With in my try I had a select statement with a good value and one with a bad value, I wanted the select to print the good and not the bad one. ====================== declare @dummy int begin try select --right('00000000' + cast(cast(round(500000,0)*10000 as int) as varchar(8)),8) right('00000000' + cast(cast(round(500000,0)*10000 as int) as varchar(8)),8) select --right('00000000' + cast(cast(round(500000,0)*10000 as int) as varchar(8)),8) right('00000000' + cast(cast(round(500000,0)*10000 as int) as varchar(8)),8) end try begin catch set @dummy = 1 end catch print @dummy

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

      :doh: try a bigint, in place of the int.. Care to explain why you are rounding the 50000, and what the casting is all about?

      Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

      V 1 Reply Last reply
      0
      • L Lost User

        :doh: try a bigint, in place of the int.. Care to explain why you are rounding the 50000, and what the casting is all about?

        Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

        V Offline
        V Offline
        vanikanc
        wrote on last edited by
        #3

        To give a bit more history, we are creating this view to feed into another application so it has to be set length. Suppose this view returns 100 rows, and I am having an arthimetic overflow in on row 56 only. I want to leave 56 and continue from 57. WhenI tried the try catch block, while it catches the error, but on once it hits 56, then the whole thing stops.

        L 1 Reply Last reply
        0
        • V vanikanc

          To give a bit more history, we are creating this view to feed into another application so it has to be set length. Suppose this view returns 100 rows, and I am having an arthimetic overflow in on row 56 only. I want to leave 56 and continue from 57. WhenI tried the try catch block, while it catches the error, but on once it hits 56, then the whole thing stops.

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

          vanikanc wrote:

          To give a bit more history

          Did you try what I suggested? Y/N?

          vanikanc wrote:

          I want to leave 56 and continue from 57.

          Filter the row out before casting it into infinity, make the result-variable bigger, or try padding it with zeroes after the cast.

          Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

          V 1 Reply Last reply
          0
          • L Lost User

            vanikanc wrote:

            To give a bit more history

            Did you try what I suggested? Y/N?

            vanikanc wrote:

            I want to leave 56 and continue from 57.

            Filter the row out before casting it into infinity, make the result-variable bigger, or try padding it with zeroes after the cast.

            Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

            V Offline
            V Offline
            vanikanc
            wrote on last edited by
            #5

            I tried with bigint - still errored out.

            L 1 Reply Last reply
            0
            • V vanikanc

              I tried with bigint - still errored out.

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

              vanikanc wrote:

              I tried with bigint - still errored out.

              Was worth a shot.

              right('00000000' + cast(cast(round(500000,0)*10000 as int) as varchar(8)),8)

              Where is the @dummy used here? 500 000 * 10 000 = 5 000 000 000. That's bigger than an int, and probably wider than eight characters. Some suggestions;

              • Lose the round function
              • Don't multiply by 10k, pad it with 4 zero's and save the string-representation.
              • If the dummy needs be multiplied by 500k, then multiply it by 5 and pad zeroes again
              • Don't limit the varchar to eight characters - use varchar(50)

              What kind of number are you trying to display? Can you give us an example of a number "before" (the original dummy) and the one "after" (the resulting dummy)?

              Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

              V 1 Reply Last reply
              0
              • L Lost User

                vanikanc wrote:

                I tried with bigint - still errored out.

                Was worth a shot.

                right('00000000' + cast(cast(round(500000,0)*10000 as int) as varchar(8)),8)

                Where is the @dummy used here? 500 000 * 10 000 = 5 000 000 000. That's bigger than an int, and probably wider than eight characters. Some suggestions;

                • Lose the round function
                • Don't multiply by 10k, pad it with 4 zero's and save the string-representation.
                • If the dummy needs be multiplied by 500k, then multiply it by 5 and pad zeroes again
                • Don't limit the varchar to eight characters - use varchar(50)

                What kind of number are you trying to display? Can you give us an example of a number "before" (the original dummy) and the one "after" (the resulting dummy)?

                Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

                V Offline
                V Offline
                vanikanc
                wrote on last edited by
                #7

                Thank you for all your suggestions! It is just some inherited code, and really don't know the in and out of it. It has been working for years, so don't want to mess with what comes in and goes out. There was an error entering the value, it was supposed to be 50 and the user keyed in 500000. So, the business wants us to put aside such errors and continue processing the data. I guess we have to code for human errors!! Thanks for all your time and suggestions!

                L 1 Reply Last reply
                0
                • V vanikanc

                  Thank you for all your suggestions! It is just some inherited code, and really don't know the in and out of it. It has been working for years, so don't want to mess with what comes in and goes out. There was an error entering the value, it was supposed to be 50 and the user keyed in 500000. So, the business wants us to put aside such errors and continue processing the data. I guess we have to code for human errors!! Thanks for all your time and suggestions!

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

                  vanikanc wrote:

                  Thank you for all your suggestions!

                  My pleasure, hope I wasn't too rude.

                  vanikanc wrote:

                  It is just some inherited code,

                  Ah, that's always a good one to include on the first post. If we see code, we assume you wrote it, and partially understand it.

                  vanikanc wrote:

                  There was an error entering the value, it was supposed to be 50 and the user keyed in 500000. So, the business wants us to put aside such errors and continue processing the data.

                  On Error Resume Next indeed. That's not how engineers work; if it fails, it fails for a reason. It get's corrected or excluded beforehand, not ignored. It's how managers work; if it fails, and nothing is burning, it's not a problem. Just ship the damn product already, we'll fix the bugs later. Perhaps this would be a good time to add a validator to the entry-field of that user, and sanitize his/her input before it gets into the system. Once the value has been entered, it should be treated as "correct". You heard about Knight Capital? Seems they had an "On Error Resume Next" idea to, and the algo kept buying stocks in packages of 100 at a time, 20 to 25 times a second - for over an half hour! (Total >440 million* losses - let's just be glad they weren't a hospital and relying on that software) Ignoring errors is the worst offence in IT; the system could have skipped customer 59 for all we know. The best approach is preached by (forgive me) PHP, and it's called "do or die". Either the app does what it should do, or there's an unexpected exception - and since we cannot guarantee that the we're still working with valid data (unexpected situation, who knows what variables are loaded and not?) we have only one realistic option; let the app die. Terminate. That's always better than continuing and writing records with an outdated identity-value after an exception, and not nowing that you're corrupting a database that was still correct when the app died. *) I checked this time whether I should use million or billion.

                  Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

                  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