473,550 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 privateExceptio n: Exception
{
public privateExceptio n(string str)
{
Console.WriteLi ne("User Defined Exception" +
this.Message+th is.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 privateExceptio n()
{

}
}
--
Andrew
Jan 27 '06 #1
4 15480
> 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 privateExceptio n: Exception
{
public privateExceptio n(string str)
{
Console.WriteLi ne("User Defined Exception" +
this.Message+th is.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 privateExceptio n()
{
}
}

class PrivateExceptio n : ApplicationExce ption
{
public PrivateExceptio n()
{}

public PrivateExceptio n(string message) : base(message)
{}

public PrivateExceptio n(string message, Exception innerException) : base(message,
innerException)
{}
}
Jan 27 '06 #2
andrewcw <an******@acw.c om> 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 privateExceptio n: Exception
{
public privateExceptio n(string str)
{
Console.WriteLi ne("User Defined Exception" +
this.Message+th is.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 privateExceptio n()
{

}
}


Well, you could override the property:

class PrivateExceptio n : Exception
{
string otherMessage;

public PrivateExceptio n (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 PrivateExceptio n : Exception
{
public PrivateExceptio n (string message) : base (message)
{
}
}

--
Jon Skeet - <sk***@pobox.co m>
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.c om> 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 privateExceptio n: Exception
{
public privateExceptio n(string str)
{
Console.WriteLi ne("User Defined Exception" +
this.Message+th is.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 privateExceptio n()
{

}
}


Well, you could override the property:

class PrivateExceptio n : Exception
{
string otherMessage;

public PrivateExceptio n (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 PrivateExceptio n : Exception
{
public PrivateExceptio n (string message) : base (message)
{
}
}

--
Jon Skeet - <sk***@pobox.co m>
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 privateExceptio n: Exception
{
public privateExceptio n(string str)
{
Console.WriteLi ne("User Defined Exception" +
this.Message+th is.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 privateExceptio n()
{
}
}

class PrivateExceptio n : ApplicationExce ption
{
public PrivateExceptio n()
{}

public PrivateExceptio n(string message) : base(message)
{}

public PrivateExceptio n(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
1845
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 "FileB" because it is being used by another process. The destination FileB does even not exists, seems to me a wrong message,
1
1844
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 IndexOutOfRangeException("Error converting the text. Possibilities are:" & ControlChars.NewLine & "- Text is too long." & ControlChars.NewLine & "- Text...
1
1621
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, however, still need to access the response stream from the server as it contains information that I need. Any ideas how I can do that? Thanks,...
10
1855
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 message to the client windows application that called that webservice function? I am using version 1.1 of the framework. WR
0
3045
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. Please help me in this concern what could be wrong?
2
1495
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 exception message. Do I need to catch my custom exception, and rethrow it as another type of exception to make the message display? I still want to...
11
1665
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: scalar.InconsistentUnits: 3 s, 4 m
0
1130
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 exception maybe like: No such file or directory: u'\u6d4b.log' This is not a clear message.
3
4547
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 Event sequence: 34707 Event occurrence: 17 Event detail code: 0 Process information:
0
7561
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7761
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7520
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7845
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5403
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3532
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3517
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1978
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1094
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.