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. Web Development
  3. ASP.NET
  4. Try Catch

Try Catch

Scheduled Pinned Locked Moved ASP.NET
discussion
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.
  • F Offline
    F Offline
    frostcox
    wrote on last edited by
    #1

    Hey i wanna start a discussion on try catch blocks. I read a lot of conflicting opinions on wether or not to use them and where or where not to use them, I just want a diffinative answer. Cheers.

    L C 2 Replies Last reply
    0
    • F frostcox

      Hey i wanna start a discussion on try catch blocks. I read a lot of conflicting opinions on wether or not to use them and where or where not to use them, I just want a diffinative answer. Cheers.

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

      Always use them around any code that may throw an exception that you need to deal with.

      One of these days I'm going to think of a really clever signature.

      F 1 Reply Last reply
      0
      • L Lost User

        Always use them around any code that may throw an exception that you need to deal with.

        One of these days I'm going to think of a really clever signature.

        F Offline
        F Offline
        frostcox
        wrote on last edited by
        #3

        Hey the thing is I know exactly when and where to use them it just seems that all through my code there are 100's of try catch blocks and I read very conflicting articles on wether or not this is best coding practice.

        L A R 3 Replies Last reply
        0
        • F frostcox

          Hey the thing is I know exactly when and where to use them it just seems that all through my code there are 100's of try catch blocks and I read very conflicting articles on wether or not this is best coding practice.

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

          Mickt1985 wrote:

          I read very conflicting articles

          Which just means that everyone has their own opinion. It's up to you to choose which one you think is right.

          One of these days I'm going to think of a really clever signature.

          1 Reply Last reply
          0
          • F frostcox

            Hey the thing is I know exactly when and where to use them it just seems that all through my code there are 100's of try catch blocks and I read very conflicting articles on wether or not this is best coding practice.

            A Offline
            A Offline
            AmitGajjar
            wrote on last edited by
            #5

            Although everyone have their own opinion but the main important thing is user should not experience unexpected behavior. if there is something going wrong you need to catch and that could be possible through try..catch and logging the messages. so resolving errors are more important then best practice... keep coding... :)

            Thanks -Amit Gajjar (MinterProject)

            1 Reply Last reply
            0
            • F frostcox

              Hey the thing is I know exactly when and where to use them it just seems that all through my code there are 100's of try catch blocks and I read very conflicting articles on wether or not this is best coding practice.

              R Offline
              R Offline
              Robert Bettinelli
              wrote on last edited by
              #6

              I understand that with tools like Codeit.right and The Visual Studio Analysis that Try Catch(s) are to be used sparingly and to catch only certain types of errors. You should try to wirte tests into the code in order to narrow the parameters of the code so that you will be able to report back to users problems. Hiding errors in Try / Catch in not the proper use of the machanic. Hope this sheds some light on the use.. Try running the code by removing all the Try/Catch and if there is a better way like a If/Then that can cover the error then it is so much better.. in Addition Try/Catch are generally slower. Regards.

              F 1 Reply Last reply
              0
              • R Robert Bettinelli

                I understand that with tools like Codeit.right and The Visual Studio Analysis that Try Catch(s) are to be used sparingly and to catch only certain types of errors. You should try to wirte tests into the code in order to narrow the parameters of the code so that you will be able to report back to users problems. Hiding errors in Try / Catch in not the proper use of the machanic. Hope this sheds some light on the use.. Try running the code by removing all the Try/Catch and if there is a better way like a If/Then that can cover the error then it is so much better.. in Addition Try/Catch are generally slower. Regards.

                F Offline
                F Offline
                frostcox
                wrote on last edited by
                #7

                Thanks very much for your reply.

                1 Reply Last reply
                0
                • F frostcox

                  Hey i wanna start a discussion on try catch blocks. I read a lot of conflicting opinions on wether or not to use them and where or where not to use them, I just want a diffinative answer. Cheers.

                  C Offline
                  C Offline
                  CommDev
                  wrote on last edited by
                  #8

                  If you are interested in executing a certain block of code irrespective of whether an exception occurs or not and still worry about catching an exception you might use the try-catch-finally block. Even if a goto statement is present in a try block, the control gets transferred to the label in the goto, only after executing the finally block. You should try and use them in your code as much as possible, especially if you suspect a particular error may crash your programme.

                  Comm100 - Leading Live Chat Software Provider

                  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