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. Exception handling..????

Exception handling..????

Scheduled Pinned Locked Moved C#
question
8 Posts 6 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.
  • R Offline
    R Offline
    Ron S
    wrote on last edited by
    #1

    hello ALL, I have a doubt. if i want to continue normally after catching the expecteed exception is it possible?? Ex:- try { int intDivVal; for (int i =o ;i<5;i++) { int Divval=10/i; } } catch(dividebyzeroexception ex) { messagebox.show(ex.message.tostring()); } i want to continue after showing the message. Thanks in advance

    Bharath.S Ron

    O T E R 4 Replies Last reply
    0
    • R Ron S

      hello ALL, I have a doubt. if i want to continue normally after catching the expecteed exception is it possible?? Ex:- try { int intDivVal; for (int i =o ;i<5;i++) { int Divval=10/i; } } catch(dividebyzeroexception ex) { messagebox.show(ex.message.tostring()); } i want to continue after showing the message. Thanks in advance

      Bharath.S Ron

      O Offline
      O Offline
      originSH
      wrote on last edited by
      #2

      yep your code there will carry right on. If you continue you have to think about anything that might have broken during an exception though i.e. was something being set to a value or a stream being opened. Carrying on can lead to losing data or more expcetions. If you want to do something with the exception and then let the exception carry on then you can catch(dividebyzeroexception ex) { messagebox.show(ex.message.tostring()); throw ex; }

      S 1 Reply Last reply
      0
      • R Ron S

        hello ALL, I have a doubt. if i want to continue normally after catching the expecteed exception is it possible?? Ex:- try { int intDivVal; for (int i =o ;i<5;i++) { int Divval=10/i; } } catch(dividebyzeroexception ex) { messagebox.show(ex.message.tostring()); } i want to continue after showing the message. Thanks in advance

        Bharath.S Ron

        T Offline
        T Offline
        Talal Sultan
        wrote on last edited by
        #3

        hello It will continue as you wrote it. Alternatively, you can use the finally statement to make sure some code is executed in all cases (try succeeded or catch executed) Talal

        -- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook

        1 Reply Last reply
        0
        • R Ron S

          hello ALL, I have a doubt. if i want to continue normally after catching the expecteed exception is it possible?? Ex:- try { int intDivVal; for (int i =o ;i<5;i++) { int Divval=10/i; } } catch(dividebyzeroexception ex) { messagebox.show(ex.message.tostring()); } i want to continue after showing the message. Thanks in advance

          Bharath.S Ron

          E Offline
          E Offline
          Eduard Keilholz
          wrote on last edited by
          #4

          Yeah, I understand you want to continue your loop after the exception is thrown... In your code the try & catch block contains the loop... try { int intDivVal; for (int i =o ;i<5;i++) { int Divval=10/i; } } catch(dividebyzeroexception ex) { messagebox.show(ex.message.tostring()); } However, the loop should contain a try & catch block in order to continue the loop try { int intDivVal; for (int i =o ;i<5;i++) { try { int Divval=10/i; } catch (Exception ex) { MessageBox.Show("Oops, 10 / " + i + " failed!"); } } } catch(dividebyzeroexception ex) { messagebox.show(ex.message.tostring()); }

          .: I love it when a plan comes together :. http://www.zonderpunt.nl

          1 Reply Last reply
          0
          • O originSH

            yep your code there will carry right on. If you continue you have to think about anything that might have broken during an exception though i.e. was something being set to a value or a stream being opened. Carrying on can lead to losing data or more expcetions. If you want to do something with the exception and then let the exception carry on then you can catch(dividebyzeroexception ex) { messagebox.show(ex.message.tostring()); throw ex; }

            S Offline
            S Offline
            Scott Dorman
            wrote on last edited by
            #5

            originSH wrote:

            catch(dividebyzeroexception ex) { messagebox.show(ex.message.tostring()); throw ex; }

            You actually want to just do a throw here rather than throw ex. The throw ex causes the original stack trace information to be lost while throw preserves it.

            Scott.


            —In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]

            O 1 Reply Last reply
            0
            • S Scott Dorman

              originSH wrote:

              catch(dividebyzeroexception ex) { messagebox.show(ex.message.tostring()); throw ex; }

              You actually want to just do a throw here rather than throw ex. The throw ex causes the original stack trace information to be lost while throw preserves it.

              Scott.


              —In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]

              O Offline
              O Offline
              originSH
              wrote on last edited by
              #6

              ahhh yeah "throw;" maps to rethrow doesn't it...

              S 1 Reply Last reply
              0
              • O originSH

                ahhh yeah "throw;" maps to rethrow doesn't it...

                S Offline
                S Offline
                Scott Dorman
                wrote on last edited by
                #7

                Yep. throw is rethrow in the IL.

                Scott.


                —In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]

                1 Reply Last reply
                0
                • R Ron S

                  hello ALL, I have a doubt. if i want to continue normally after catching the expecteed exception is it possible?? Ex:- try { int intDivVal; for (int i =o ;i<5;i++) { int Divval=10/i; } } catch(dividebyzeroexception ex) { messagebox.show(ex.message.tostring()); } i want to continue after showing the message. Thanks in advance

                  Bharath.S Ron

                  R Offline
                  R Offline
                  Rudolf Jan
                  wrote on last edited by
                  #8

                  You should think about continuation that makes sense. You may return to an input for example, or substitute the illegal result with something that makes sense for you application. Just ignoring the exception is generally not a very good idea.

                  Rudolf Heijink

                  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