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

Exception

Scheduled Pinned Locked Moved C#
csharphelptutorialquestion
7 Posts 4 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.
  • J Offline
    J Offline
    jojoba2010
    wrote on last edited by
    #1

    How to get exception Code in C#? This Code just Show Error Message : try { } catch(Exception ex) { messagebox.show(ex.Message); }

    S L 2 Replies Last reply
    0
    • J jojoba2010

      How to get exception Code in C#? This Code just Show Error Message : try { } catch(Exception ex) { messagebox.show(ex.Message); }

      S Offline
      S Offline
      SeMartens
      wrote on last edited by
      #2

      Hi, exception is a way to provide information about an unusual behavior in a method. Sometimes this behavior is caused by an error. What you want is the error code. So the "default" Exception class you are catching does not provide an error code http://msdn.microsoft.com/en-us/library/system.exception.aspx[^] But if the specific class of the exception thrown by the called method contains a code, than you can receive this code by accessing the property from the exception (you have to cast before or catch a more specific type). If you need further help I recommend to post the code also, causing the exception. Regards Sebastian

      It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

      J 1 Reply Last reply
      0
      • S SeMartens

        Hi, exception is a way to provide information about an unusual behavior in a method. Sometimes this behavior is caused by an error. What you want is the error code. So the "default" Exception class you are catching does not provide an error code http://msdn.microsoft.com/en-us/library/system.exception.aspx[^] But if the specific class of the exception thrown by the called method contains a code, than you can receive this code by accessing the property from the exception (you have to cast before or catch a more specific type). If you need further help I recommend to post the code also, causing the exception. Regards Sebastian

        It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

        J Offline
        J Offline
        jojoba2010
        wrote on last edited by
        #3
        1. for example : System.FormatException try { int i = int.Parse("Hi Thanks for your Help!"); } catch (Exception ex) { Type tp= ex.GetType(); } catch (FormatException Fex) { Type tp= ex.GetType(); } 2) where we can get all Exception types?
        S D 2 Replies Last reply
        0
        • J jojoba2010
          1. for example : System.FormatException try { int i = int.Parse("Hi Thanks for your Help!"); } catch (Exception ex) { Type tp= ex.GetType(); } catch (FormatException Fex) { Type tp= ex.GetType(); } 2) where we can get all Exception types?
          S Offline
          S Offline
          SeMartens
          wrote on last edited by
          #4
          1. you have to catch the FormatException first. And as second one the common Exception. When not, the FormatException will never be catched, because a FormatException is an Exception. 2) Nowhere, because Exception are classes which can be derived from. So there are thousands of Exception types out there (waiting to be catched :-D ) (For all framework exceptions you can browse through msdn...) 3) Maybe you can explain what you want to achieve? To get an idea for exception handlung start reading this msdn article: http://msdn.microsoft.com/en-us/library/ms173160.aspx[^] Regards Sebastian

          It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

          J 1 Reply Last reply
          0
          • S SeMartens
            1. you have to catch the FormatException first. And as second one the common Exception. When not, the FormatException will never be catched, because a FormatException is an Exception. 2) Nowhere, because Exception are classes which can be derived from. So there are thousands of Exception types out there (waiting to be catched :-D ) (For all framework exceptions you can browse through msdn...) 3) Maybe you can explain what you want to achieve? To get an idea for exception handlung start reading this msdn article: http://msdn.microsoft.com/en-us/library/ms173160.aspx[^] Regards Sebastian

            It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.

            J Offline
            J Offline
            jojoba2010
            wrote on last edited by
            #5

            Before all Thanks for your attention and Help ! I want to translate Exception to my Language (Persian,Farsi) then show the translate exception.(Note: I dont want to write down the error in catch like bellow: try { } catch { messagebox.show("Not like this"); } OR try { } catch(Exception ex) { messagebox.show("Not like this"); } OR try { } catch(FormatException ex) { messagebox.show("Not like this"); }

            1 Reply Last reply
            0
            • J jojoba2010
              1. for example : System.FormatException try { int i = int.Parse("Hi Thanks for your Help!"); } catch (Exception ex) { Type tp= ex.GetType(); } catch (FormatException Fex) { Type tp= ex.GetType(); } 2) where we can get all Exception types?
              D Offline
              D Offline
              David Skelly
              wrote on last edited by
              #6

              Isn't this exactly the same question that you posted three hours ago under the title ERROR? It is generally considered bad form to post the same question multiple times.

              1 Reply Last reply
              0
              • J jojoba2010

                How to get exception Code in C#? This Code just Show Error Message : try { } catch(Exception ex) { messagebox.show(ex.Message); }

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

                You have been give the answer to this already; try reading the MSDN documentation on C# exceptions.

                MVP 2010 - are they mad?

                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