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. Is there a way to get a list of all exceptions that can be thrown by a program....

Is there a way to get a list of all exceptions that can be thrown by a program....

Scheduled Pinned Locked Moved C#
helpcsharptestingdebuggingbeta-testing
12 Posts 8 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.
  • E Offline
    E Offline
    edaindia
    wrote on last edited by
    #1

    I am testing a c# application and one of the issues I am finding is the application throws unhandled exception error once in a while which leads to a debug and fix cycle.... Is there a way to get a list of all possible exceptions that can be thrown by the application and the line number where it can be thrown.... Regards Ajay

    J S L L realJSOPR 6 Replies Last reply
    0
    • E edaindia

      I am testing a c# application and one of the issues I am finding is the application throws unhandled exception error once in a while which leads to a debug and fix cycle.... Is there a way to get a list of all possible exceptions that can be thrown by the application and the line number where it can be thrown.... Regards Ajay

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

      Hope I'm not asking a dumb question but is the code you're executing within a try / catch block? Second question is do you what is causing the exception yet?

      E 1 Reply Last reply
      0
      • E edaindia

        I am testing a c# application and one of the issues I am finding is the application throws unhandled exception error once in a while which leads to a debug and fix cycle.... Is there a way to get a list of all possible exceptions that can be thrown by the application and the line number where it can be thrown.... Regards Ajay

        S Offline
        S Offline
        sanforjackass
        wrote on last edited by
        #3

        try this: try { ..... ..... } catch(Exception ex) { ...... ...... }

        1 Reply Last reply
        0
        • E edaindia

          I am testing a c# application and one of the issues I am finding is the application throws unhandled exception error once in a while which leads to a debug and fix cycle.... Is there a way to get a list of all possible exceptions that can be thrown by the application and the line number where it can be thrown.... Regards Ajay

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          edaindia wrote:

          a list of all possible exceptions

          No. FYI: The list of things that can go wrong in Windows would be infinite. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


          Merry Christmas and a Happy New Year to all.


          realJSOPR M 2 Replies Last reply
          0
          • E edaindia

            I am testing a c# application and one of the issues I am finding is the application throws unhandled exception error once in a while which leads to a debug and fix cycle.... Is there a way to get a list of all possible exceptions that can be thrown by the application and the line number where it can be thrown.... Regards Ajay

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

            edaindia wrote:

            Is there a way to get a list of all possible exceptions that can be thrown by the application and the line number where it can be thrown

            Not that I know of. Well, that's a bit of a lie; you could loop through all the assemblies that are loaded, and list those classes that inherit from Exception. The programmers should already be handling the errors that they can expect locally with a try-catch block, as has been noted a few times. The exceptions that remain should be handled in the "global exception handler". There's an event called ThreadException[^] that gets raised whenever there's some exception that didn't get handled by the try-catch blocks. If you don't handle those, you'll get an ugly exception-screen. Now, you want a list of all the exceptions that can occur there? Well, everything that's derived from Exception - hence the suggestion to just log "everything" that triggers the ThreadException event. Good luck :)

            I are Troll :suss:

            E 1 Reply Last reply
            0
            • L Luc Pattyn

              edaindia wrote:

              a list of all possible exceptions

              No. FYI: The list of things that can go wrong in Windows would be infinite. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              Merry Christmas and a Happy New Year to all.


              realJSOPR Offline
              realJSOPR Offline
              realJSOP
              wrote on last edited by
              #6

              And more often than not, there's not a damn thing you can do about it.

              .45 ACP - because shooting twice is just silly
              -----
              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
              -----
              "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

              1 Reply Last reply
              0
              • E edaindia

                I am testing a c# application and one of the issues I am finding is the application throws unhandled exception error once in a while which leads to a debug and fix cycle.... Is there a way to get a list of all possible exceptions that can be thrown by the application and the line number where it can be thrown.... Regards Ajay

                realJSOPR Offline
                realJSOPR Offline
                realJSOP
                wrote on last edited by
                #7

                Just put a try/catch block around everything that could fail, and there you have it.

                .45 ACP - because shooting twice is just silly
                -----
                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                -----
                "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                1 Reply Last reply
                0
                • J JasonLee07

                  Hope I'm not asking a dumb question but is the code you're executing within a try / catch block? Second question is do you what is causing the exception yet?

                  E Offline
                  E Offline
                  edaindia
                  wrote on last edited by
                  #8

                  JasonLee07 wrote:

                  Hope I'm not asking a dumb question but is the code you're executing within a try / catch block?

                  Some of the code is ... and some is not.... The current approach is I test various features of the application until it pop-ups an unhandled exception after which the offending piece of code is encapsulated in an try {...} catch {...} block What I was looking for is a formal method of getting a list of all possible code blocks which can throw an exception and performing a code review to ensure that all exceptions are properly handled.....

                  JasonLee07 wrote:

                  Second question is do you what is causing the exception yet?

                  I have root caused the exceptions which were triggered by my testcases.

                  1 Reply Last reply
                  0
                  • L Lost User

                    edaindia wrote:

                    Is there a way to get a list of all possible exceptions that can be thrown by the application and the line number where it can be thrown

                    Not that I know of. Well, that's a bit of a lie; you could loop through all the assemblies that are loaded, and list those classes that inherit from Exception. The programmers should already be handling the errors that they can expect locally with a try-catch block, as has been noted a few times. The exceptions that remain should be handled in the "global exception handler". There's an event called ThreadException[^] that gets raised whenever there's some exception that didn't get handled by the try-catch blocks. If you don't handle those, you'll get an ugly exception-screen. Now, you want a list of all the exceptions that can occur there? Well, everything that's derived from Exception - hence the suggestion to just log "everything" that triggers the ThreadException event. Good luck :)

                    I are Troll :suss:

                    E Offline
                    E Offline
                    edaindia
                    wrote on last edited by
                    #9

                    Eddy Vluggen wrote:

                    Not that I know of. Well, that's a bit of a lie; you could loop through all the assemblies that are loaded, and list those classes that inherit from Exception.

                    Is there any way to do this?

                    Eddy Vluggen wrote:

                    The programmers should already be handling the errors that they can expect locally with a try-catch block,

                    My concern was about finding those sections of code which should be within a try catch block, but are not. If the exception was caught at the right location the programmer would have various options (e.g. abort,retry,ignore). Hence the emphasis on finding a formal way to identifying all code sections which can throw an exception and resolving them through a code review. A global exception handler would be my last resort at the time of actual deployment. Thanks for the reply....

                    L 1 Reply Last reply
                    0
                    • E edaindia

                      Eddy Vluggen wrote:

                      Not that I know of. Well, that's a bit of a lie; you could loop through all the assemblies that are loaded, and list those classes that inherit from Exception.

                      Is there any way to do this?

                      Eddy Vluggen wrote:

                      The programmers should already be handling the errors that they can expect locally with a try-catch block,

                      My concern was about finding those sections of code which should be within a try catch block, but are not. If the exception was caught at the right location the programmer would have various options (e.g. abort,retry,ignore). Hence the emphasis on finding a formal way to identifying all code sections which can throw an exception and resolving them through a code review. A global exception handler would be my last resort at the time of actual deployment. Thanks for the reply....

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

                      edaindia wrote:

                      Is there any way to do this?

                      Yes. Loop through all the assemblies in your domain, enumerate all classes within that assembly and check what they are made (derived) of. Will that get you a list of all exceptions that can be thrown? Well, yes and no: it will give you a list of known exception-classes. Some classes might be generated at runtime, some are wrapped in global classes and only carry a cryptic number from the filesystem. Another point would be that you'd have some exceptions on that list that would be very rare. In other words, you'd end up with misleading information - preparing for StackOverflow-exceptions that simply never occur.

                      edaindia wrote:

                      My concern was about finding those sections of code which should be within a try catch block, but are not.

                      With all respect, that's the programmers' own responsibility. You don't want an "on error resume next" system, and you don't want to force a user into deciding "ignore", "retry" and "cancel" for a StackOverflow. They'll get confused. I find myself often clicking the X-button in such a situation.

                      edaindia wrote:

                      A global exception handler would be my last resort at the time of actual deployment.

                      Make it the first resort, and log everything that happens. Followup on everything, untill they slowly die out. You can't avoid falling down, there will always be an exception that you didn't cater for. Or worse, a method that fails without throwing an exception. You don't want a customer relying on a backup that failed silently! Once that you know that there will be an unhandled exception, your best option is to divine a strategy to handle them. Ie, implement that global exception-handler, and follow up on those rare exceptions that could actually harm your clients. Think about it; what you're suggesting is closed to the default behaviour of a .NET application. It makes sense to shut-down the application, since there's an exception. And there's no way that you're going to surround each and every method with a OutOfMemoryException - some things can be translated to a simple message from a global point.

                      edaindia wrote:

                      Hence the emphasis on finding a formal way to identifying all code sections which can throw an exception and resolving them through a code review.

                      Sounds rathe

                      1 Reply Last reply
                      0
                      • L Luc Pattyn

                        edaindia wrote:

                        a list of all possible exceptions

                        No. FYI: The list of things that can go wrong in Windows would be infinite. :)

                        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                        Merry Christmas and a Happy New Year to all.


                        M Offline
                        M Offline
                        Mycroft Holmes
                        wrote on last edited by
                        #11

                        Isn't that called StackOverflow?

                        Never underestimate the power of human stupidity RAH

                        1 Reply Last reply
                        0
                        • E edaindia

                          I am testing a c# application and one of the issues I am finding is the application throws unhandled exception error once in a while which leads to a debug and fix cycle.... Is there a way to get a list of all possible exceptions that can be thrown by the application and the line number where it can be thrown.... Regards Ajay

                          P Offline
                          P Offline
                          PIEBALDconsult
                          wrote on last edited by
                          #12

                          No.

                          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