473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

overriding exception message

I wanted to create an exception handler for certain processing I do - but
although I can 'throw' to the constructor with a parameter, I cannot
override the exception message property, the error says its read only. How
can or if a person can create the override ?

class privateException: Exception
{
public privateException(string str)
{
Console.WriteLine("User Defined Exception" +
this.Message+this.StackTrace);
// this.Message=" Special Error " + str
// you cannot seem to create modify the message.
// this input could cause some additional interaction - maybe here
// would be where a file could be written
}
public privateException()
{

}
}
--
Andrew
Jan 27 '06 #1
4 15465
> I wanted to create an exception handler for certain processing I do -
but although I can 'throw' to the constructor with a parameter, I
cannot override the exception message property, the error says its
read only. How can or if a person can create the override ?

class privateException: Exception
{
public privateException(string str)
{
Console.WriteLine("User Defined Exception" +
this.Message+this.StackTrace);
// this.Message=" Special Error " + str
// you cannot seem to create modify the message.
// this input could cause some additional interaction -
maybe here
// would be where a file could be written
}
public privateException()
{
}
}

class PrivateException : ApplicationException
{
public PrivateException()
{}

public PrivateException(string message) : base(message)
{}

public PrivateException(string message, Exception innerException) : base(message,
innerException)
{}
}
Jan 27 '06 #2
andrewcw <an******@acw.com> wrote:
I wanted to create an exception handler for certain processing I do - but
although I can 'throw' to the constructor with a parameter, I cannot
override the exception message property, the error says its read only. How
can or if a person can create the override ?

class privateException: Exception
{
public privateException(string str)
{
Console.WriteLine("User Defined Exception" +
this.Message+this.StackTrace);
// this.Message=" Special Error " + str
// you cannot seem to create modify the message.
// this input could cause some additional interaction - maybe here
// would be where a file could be written
}
public privateException()
{

}
}


Well, you could override the property:

class PrivateException : Exception
{
string otherMessage;

public PrivateException (string message)
{
otherMessage = message;
}

public override string Message
{
get { return otherMessage; }
}
}

However, you might as well pass the message to the base constructor in
the first place:

class PrivateException : Exception
{
public PrivateException (string message) : base (message)
{
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 27 '06 #3
Thankyou ! I really appreciate the help !
--
Andrew
"Jon Skeet [C# MVP]" wrote:
andrewcw <an******@acw.com> wrote:
I wanted to create an exception handler for certain processing I do - but
although I can 'throw' to the constructor with a parameter, I cannot
override the exception message property, the error says its read only. How
can or if a person can create the override ?

class privateException: Exception
{
public privateException(string str)
{
Console.WriteLine("User Defined Exception" +
this.Message+this.StackTrace);
// this.Message=" Special Error " + str
// you cannot seem to create modify the message.
// this input could cause some additional interaction - maybe here
// would be where a file could be written
}
public privateException()
{

}
}


Well, you could override the property:

class PrivateException : Exception
{
string otherMessage;

public PrivateException (string message)
{
otherMessage = message;
}

public override string Message
{
get { return otherMessage; }
}
}

However, you might as well pass the message to the base constructor in
the first place:

class PrivateException : Exception
{
public PrivateException (string message) : base (message)
{
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 28 '06 #4
Thanks ! I really appreciate the help !
--
Andrew
"chris martin" wrote:
I wanted to create an exception handler for certain processing I do -
but although I can 'throw' to the constructor with a parameter, I
cannot override the exception message property, the error says its
read only. How can or if a person can create the override ?

class privateException: Exception
{
public privateException(string str)
{
Console.WriteLine("User Defined Exception" +
this.Message+this.StackTrace);
// this.Message=" Special Error " + str
// you cannot seem to create modify the message.
// this input could cause some additional interaction -
maybe here
// would be where a file could be written
}
public privateException()
{
}
}

class PrivateException : ApplicationException
{
public PrivateException()
{}

public PrivateException(string message) : base(message)
{}

public PrivateException(string message, Exception innerException) : base(message,
innerException)
{}
}

Jan 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rene | last post by:
Hi, Maybe I'm wrong, but we get an exceptoin on File.Move ("FileA", "FileB" ) because FileA is still in use (sharing violation), but the Exception.Message says: Process cannot access the file...
1
by: Chris Leffer | last post by:
Hi. I have a function that raises a custom exception message. I am trying to divide the message in 3 lines, but could not successfuly display the message. Those were my tries: Throw New...
1
by: iana_kosio | last post by:
Hi, I am using HttpWebRequest class to communicate with remote server. In some cases the server would return 5xx status code which results in HttpWebRequest object throwing an exception. I,...
10
by: WhiskyRomeo | last post by:
I have webservices functions that return datasets. If a database errors happens, try catch statements can be used in the webservice to detect and handle them. However, how do I return that...
0
by: gunjanhshah | last post by:
Hello My system reports the following application event log. The log is due to my web application which is built upon asp.net and sql server 2000 and uses Active directory users to authenticate....
2
by: bdgreen | last post by:
Hi, I made a custom exception, derived from ApplicationException. If the exception is thrown, the erroring web page shows the line of code where I throw exception, and doesn't display the...
11
by: Russ P. | last post by:
I am baffled about why my exception messages are not displaying properly. I have a class that represents physical scalars with units. If I type I should get something like this: ...
0
by: WaterWalk | last post by:
Until Python 2.5, the exception object still uses ansi string. Thus, in the following example: f = open(u"\u6d4b.log") Suppose the file to open does not exist, the output message of the...
3
by: chandhrakv | last post by:
Event code: 3005 Event message: An unhandled exception has occurred. Event time: 11/18/2009 3:03:53 PM Event time (UTC): 11/18/2009 9:33:53 AM Event ID: ef3014ea80424b00b1bc2e7095fffe4c ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.