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 doubt...

Exception handling doubt...

Scheduled Pinned Locked Moved C#
question
15 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.
  • S Software_Specialist

    And how could i do that..how to add the original exception as an innerException to the existing one ? Thanks

    N Offline
    N Offline
    Not Active
    wrote on last edited by
    #5

    I love seeing questions like this from some calling themself Software_Specialist. It gives me hope that there is job security for me. :laugh:


    only two letters away from being an asset

    C 1 Reply Last reply
    0
    • S Software_Specialist

      Well i have lil doubt about handling exception... Well i have created a ABCException class based over Exception class. which includes ABCException class constructors with differnt parameters like.. class STAFException : Exception { public ABCException() {...} public ABCException(Uint32 cc) {...} public ABCException(Uint32 cc, string message) : base(message) {...} public ABCException(string message) : base(message){...} } Now my question is ... for instance look at the below mentioned method public IDictionary createInstance() { Hashtable treemap = new Hashtable(); treemap.Add("map-class-name", _mapClassDef["name"]); return treemap; } So if i want to handle its exception...is the below method correct or am i doing it wrong... public IDictionary createInstance() { try { Hashtable treemap = new Hashtable(); treemap.Add("map-class-name", _mapClassDef["name"]); return treemap; } catch(Exception e) { throw new ABCException("unknown exception: " + ee.Message); } } Is it right way to deal with it...can i use this approach with my other methods aswell..? Thanks

      G Offline
      G Offline
      gumi_r msn com
      wrote on last edited by
      #6

      On top of the InnerException issue, you should not catch general System.Exception. There are very few cases where this is justified. Keep in mind that you should only catch exceptions that you know how to deal with or where you can add valuable information before throwing it to the calling code where "someone" will know what to do with it. If you use catch System.Exception you can be catching any kind of exception that you may have no idea how to handle and that most probably you shouldn't even be trying to handle. In these cases wrapping the exception in your own custom made exception and throwing it does not add any valuable information and is completely pointless, you are only bloating the exception information before it reaches some relevant code. So, analyse you're class and method and see what type of exceptions you can get that can be handled by your class or where your class can add valuable debugging information to the consumer and catch only those exceptions. If not, just don't catch them at all...the calling code will take care of it, or the caller of the calling, etc, etc.

      1 Reply Last reply
      0
      • N Not Active

        I love seeing questions like this from some calling themself Software_Specialist. It gives me hope that there is job security for me. :laugh:


        only two letters away from being an asset

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #7

        :-D

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        D 1 Reply Last reply
        0
        • C CPallini

          :-D

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

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

          Have you seen the O/S and toys on cell phones lately? What utter crap! It's only a matter of time before it's simply not worth having your entire customer base pissed at you because you outsourced software development to a company that has too many people who don't know what their doing. At least I hope that's the case! :~

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          C 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Have you seen the O/S and toys on cell phones lately? What utter crap! It's only a matter of time before it's simply not worth having your entire customer base pissed at you because you outsourced software development to a company that has too many people who don't know what their doing. At least I hope that's the case! :~

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            C Offline
            C Offline
            CPallini
            wrote on last edited by
            #9

            Well, Knuth says programming is an art. How many artists you can see around you? Of course there are several reasons behind this scenario: There is a strong request for software and employers tend to prefer cheap teams; usually Project Managers insist on deadlines more than on software quality; new languages and tools are often presented as accessible to untrained people (and indeed they are, but good programming has NOT such accessibility) and so on... :)

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

            D 2 Replies Last reply
            0
            • C CPallini

              Well, Knuth says programming is an art. How many artists you can see around you? Of course there are several reasons behind this scenario: There is a strong request for software and employers tend to prefer cheap teams; usually Project Managers insist on deadlines more than on software quality; new languages and tools are often presented as accessible to untrained people (and indeed they are, but good programming has NOT such accessibility) and so on... :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

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

              CPallini wrote:

              Well, Knuth says programming is an art.

              How true that is!

              CPallini wrote:

              How many artists you can see around you?

              I'm alone around here, so I'm the only one. This place has probably given me the most frustrating experience of my life simply supporting all the systems around here. The simplest of ideas are the most difficult concepts to get people to do. I mean stuff we would normally just expect to happen automatically is not being done. For instance, looking a a trouble ticket that says "Computer not working". That's it! Nothing else! :wtf: WHICH computer? Who's the contact? Who reported the problem? WHAT'S THE FRIGGIN' PROBLEM DESCRIPTION?? Don't get me started about how people write the code that makes up custom systems around here! Talk about unsupportable... I wish I could just unload the stories upon the "Coding Horrors" forum, but that would get me fired in a heartbeat.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              1 Reply Last reply
              0
              • C CPallini

                Well, Knuth says programming is an art. How many artists you can see around you? Of course there are several reasons behind this scenario: There is a strong request for software and employers tend to prefer cheap teams; usually Project Managers insist on deadlines more than on software quality; new languages and tools are often presented as accessible to untrained people (and indeed they are, but good programming has NOT such accessibility) and so on... :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

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

                CPallini wrote:

                There is a strong request for software and employers tend to prefer cheap teams

                Company executives/managers still haven't heard of the phrase "You get what you pay for"!

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007

                C L 2 Replies Last reply
                0
                • D Dave Kreskowiak

                  CPallini wrote:

                  There is a strong request for software and employers tend to prefer cheap teams

                  Company executives/managers still haven't heard of the phrase "You get what you pay for"!

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                       2006, 2007

                  C Offline
                  C Offline
                  CPallini
                  wrote on last edited by
                  #12

                  Dave Kreskowiak wrote:

                  Company executives/managers still haven't heard of the phrase "You get what you pay for"!

                  No, they had. The problem is that they don't get the software, they just sell it to other people :-D

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                  1 Reply Last reply
                  0
                  • D Dave Kreskowiak

                    CPallini wrote:

                    There is a strong request for software and employers tend to prefer cheap teams

                    Company executives/managers still haven't heard of the phrase "You get what you pay for"!

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                         2006, 2007

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

                    Dave Kreskowiak wrote:

                    Company executives/managers still haven't heard of the phrase "You get what you pay for"!

                    maybe it does not apply to executives/managers ?

                    Luc Pattyn [My Articles] [Forum Guidelines]

                    D 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      Dave Kreskowiak wrote:

                      Company executives/managers still haven't heard of the phrase "You get what you pay for"!

                      maybe it does not apply to executives/managers ?

                      Luc Pattyn [My Articles] [Forum Guidelines]

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

                      Oh, it applies to them most of all! :laugh: How many compaines have gone under, run by overpaid executives just tem to fleece the company and the shareholders? Enron, Adelphia, KMart, WorldCom, ...

                      A guide to posting questions on CodeProject[^]
                      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                           2006, 2007

                      1 Reply Last reply
                      0
                      • S Software_Specialist

                        Well i have lil doubt about handling exception... Well i have created a ABCException class based over Exception class. which includes ABCException class constructors with differnt parameters like.. class STAFException : Exception { public ABCException() {...} public ABCException(Uint32 cc) {...} public ABCException(Uint32 cc, string message) : base(message) {...} public ABCException(string message) : base(message){...} } Now my question is ... for instance look at the below mentioned method public IDictionary createInstance() { Hashtable treemap = new Hashtable(); treemap.Add("map-class-name", _mapClassDef["name"]); return treemap; } So if i want to handle its exception...is the below method correct or am i doing it wrong... public IDictionary createInstance() { try { Hashtable treemap = new Hashtable(); treemap.Add("map-class-name", _mapClassDef["name"]); return treemap; } catch(Exception e) { throw new ABCException("unknown exception: " + ee.Message); } } Is it right way to deal with it...can i use this approach with my other methods aswell..? Thanks

                        V Offline
                        V Offline
                        Vikram A Punathambekar
                        wrote on last edited by
                        #15

                        NEVER catch an exception that you cannot handle. In your case, don't catch the ABCException; let it propogate up the call stack. It should be the caller's responsibility to code defensively and handle exceptions.

                        Cheers, Vıkram.


                        After all is said and done, much is said and little is done.

                        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