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. how to set the value to exception object?

how to set the value to exception object?

Scheduled Pinned Locked Moved C#
tutorialquestion
12 Posts 3 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.
  • G Guffa

    What value? You can create an Exception object with any message you like: new ApplicationException("Nu sket det sig rejält, må jag säga.") You can also create specific Exception objects for different kinds of errors. Some examples: new ArgumentNullException("path", "The path argument may not be null.") new NullReferenceException("The operation resulted in a null reference.") new IndexOutOfRangeException("The position has to be in the range 0 to 9.")

    --- It's amazing to see how much work some people will go through just to avoid a little bit of work.

    B Offline
    B Offline
    babutkchn
    wrote on last edited by
    #3

    but for this i've to set the value to the property in the class as follows. this.Message = "msg"; or exception.Message="msg"; how to set that??

    C G 2 Replies Last reply
    0
    • G Guffa

      What value? You can create an Exception object with any message you like: new ApplicationException("Nu sket det sig rejält, må jag säga.") You can also create specific Exception objects for different kinds of errors. Some examples: new ArgumentNullException("path", "The path argument may not be null.") new NullReferenceException("The operation resulted in a null reference.") new IndexOutOfRangeException("The position has to be in the range 0 to 9.")

      --- It's amazing to see how much work some people will go through just to avoid a little bit of work.

      B Offline
      B Offline
      babutkchn
      wrote on last edited by
      #4

      for example in the following code i've set the value to both source and message.but the application shows error for the MEssage property. I need the soution for this.i need to set the value as in the code. how to set that? Kindly tell me? public class CustomExp : ApplicationException { public void cust(String msg) { this.Source = "test"; this.Message = "testing"; } } babu

      C G 2 Replies Last reply
      0
      • B babutkchn

        but for this i've to set the value to the property in the class as follows. this.Message = "msg"; or exception.Message="msg"; how to set that??

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #5

        Set the message property of the exception in the constructor.


        Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

        B 1 Reply Last reply
        0
        • B babutkchn

          for example in the following code i've set the value to both source and message.but the application shows error for the MEssage property. I need the soution for this.i need to set the value as in the code. how to set that? Kindly tell me? public class CustomExp : ApplicationException { public void cust(String msg) { this.Source = "test"; this.Message = "testing"; } } babu

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #6

          Set the value of message in the constructor, as in the examples given in the other thread you started.


          Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

          1 Reply Last reply
          0
          • B babutkchn

            but for this i've to set the value to the property in the class as follows. this.Message = "msg"; or exception.Message="msg"; how to set that??

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #7

            I explained how you do that in the other thread. If you didn't create mutiple threads about the same thing, the confusion would be less.

            --- It's amazing to see how much work some people will go through just to avoid a little bit of work.

            1 Reply Last reply
            0
            • B babutkchn

              for example in the following code i've set the value to both source and message.but the application shows error for the MEssage property. I need the soution for this.i need to set the value as in the code. how to set that? Kindly tell me? public class CustomExp : ApplicationException { public void cust(String msg) { this.Source = "test"; this.Message = "testing"; } } babu

              G Offline
              G Offline
              Guffa
              wrote on last edited by
              #8

              I explained how you do that in the other thread. If you didn't create mutiple threads about the same thing, the confusion would be less.

              --- It's amazing to see how much work some people will go through just to avoid a little bit of work.

              1 Reply Last reply
              0
              • C Colin Angus Mackay

                Set the message property of the exception in the constructor.


                Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

                B Offline
                B Offline
                babutkchn
                wrote on last edited by
                #9

                yes. as you said i put the message property in constructor. even thne it shows the error i've mentioned in prev message. babu

                C 1 Reply Last reply
                0
                • B babutkchn

                  yes. as you said i put the message property in constructor. even thne it shows the error i've mentioned in prev message. babu

                  C Offline
                  C Offline
                  Colin Angus Mackay
                  wrote on last edited by
                  #10

                  babutkchn wrote:

                  as you said i put the message property in constructor. even thne it shows the error i've mentioned in prev message

                  Did you call it right: public MyException : ApplicationException { public MyException(string message) : base (message) { } }


                  Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

                  B 1 Reply Last reply
                  0
                  • C Colin Angus Mackay

                    babutkchn wrote:

                    as you said i put the message property in constructor. even thne it shows the error i've mentioned in prev message

                    Did you call it right: public MyException : ApplicationException { public MyException(string message) : base (message) { } }


                    Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

                    B Offline
                    B Offline
                    babutkchn
                    wrote on last edited by
                    #11

                    yes.

                    C 1 Reply Last reply
                    0
                    • B babutkchn

                      yes.

                      C Offline
                      C Offline
                      Colin Angus Mackay
                      wrote on last edited by
                      #12

                      Then the exception should have the message that is passed in to the constructor. Which is as it should be.


                      Upcoming Scottish Developers events: * Glasgow: Tell us what you want to see in 2007 My: Website | Blog | Photos

                      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