how to set the value to exception object?
-
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.
-
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.
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
-
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??
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
-
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
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
-
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??
-
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
-
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
-
yes. as you said i put the message property in constructor. even thne it shows the error i've mentioned in prev message. babu
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
-
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
-
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