473,463 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

System.Exception

Hi

Is there any method to change System. Exception. Message property in derived
exception's constructor? I need runtime class' information to initialize
this property, but it's readonly.

Thaks.
Nov 16 '05 #1
11 3780
Ivan A. <iv************@hotmail.com> wrote:
Is there any method to change System. Exception. Message property in derived
exception's constructor? I need runtime class' information to initialize
this property, but it's readonly.


Pass it in in the call to the base constructor. For example:

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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Hi

Thanx for reply, but base class constructor is called before I can do
something in my own constructor so this is not solution to my problem.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Ivan A. <iv************@hotmail.com> wrote:
Is there any method to change System. Exception. Message property in derived exception's constructor? I need runtime class' information to initialize
this property, but it's readonly.


Pass it in in the call to the base constructor. For example:

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

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

Nov 16 '05 #3
Ivan,
In addition to passing it to the constructor, if you are creating a derived
class, you can override the Message property.

Also remember that Exception.Message is intended for user display,
Exception.ToString includes "runtime class' information" by virtue of the
stack trace property.

Hope this helps
Jay

"Ivan A." <iv************@hotmail.com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
Hi

Is there any method to change System. Exception. Message property in derived exception's constructor? I need runtime class' information to initialize
this property, but it's readonly.

Thaks.

Nov 16 '05 #4
Ivan,
In addition to passing it to the constructor, if you are creating a derived
class, you can override the Message property.

Also remember that Exception.Message is intended for user display,
Exception.ToString includes "runtime class' information" by virtue of the
stack trace property.

Hope this helps
Jay

"Ivan A." <iv************@hotmail.com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
Hi

Is there any method to change System. Exception. Message property in derived exception's constructor? I need runtime class' information to initialize
this property, but it's readonly.

Thaks.

Nov 16 '05 #5
Hi

Thanks, I'll try that, but I think it will work!

I found another solution, in constructor of my exception I compute exception
Message and then re-throw the same exception with this message string as
constructor parameter for new exception. So client gets new exception with
proper message property. Is this ok?
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:O1*************@TK2MSFTNGP10.phx.gbl...
Ivan,
In addition to passing it to the constructor, if you are creating a derived class, you can override the Message property.

Also remember that Exception.Message is intended for user display,
Exception.ToString includes "runtime class' information" by virtue of the
stack trace property.

Hope this helps
Jay

"Ivan A." <iv************@hotmail.com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
Hi

Is there any method to change System. Exception. Message property in

derived
exception's constructor? I need runtime class' information to initialize
this property, but it's readonly.

Thaks.


Nov 16 '05 #6
Hi

Thanks, I'll try that, but I think it will work!

I found another solution, in constructor of my exception I compute exception
Message and then re-throw the same exception with this message string as
constructor parameter for new exception. So client gets new exception with
proper message property. Is this ok?
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:O1*************@TK2MSFTNGP10.phx.gbl...
Ivan,
In addition to passing it to the constructor, if you are creating a derived class, you can override the Message property.

Also remember that Exception.Message is intended for user display,
Exception.ToString includes "runtime class' information" by virtue of the
stack trace property.

Hope this helps
Jay

"Ivan A." <iv************@hotmail.com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
Hi

Is there any method to change System. Exception. Message property in

derived
exception's constructor? I need runtime class' information to initialize
this property, but it's readonly.

Thaks.


Nov 16 '05 #7
NO!

I would use the constructor As Jon identified:

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

If you need to "compute" the message to pass to "base (message)" I would
either use a static method to compute the message based to the base or I
would simply override the Message property.

Hope this helps
Jay
"Ivan A." <iv************@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi

Thanks, I'll try that, but I think it will work!

I found another solution, in constructor of my exception I compute exception Message and then re-throw the same exception with this message string as
constructor parameter for new exception. So client gets new exception with
proper message property. Is this ok?
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:O1*************@TK2MSFTNGP10.phx.gbl...
Ivan,
In addition to passing it to the constructor, if you are creating a

derived
class, you can override the Message property.

Also remember that Exception.Message is intended for user display,
Exception.ToString includes "runtime class' information" by virtue of the stack trace property.

Hope this helps
Jay

"Ivan A." <iv************@hotmail.com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
Hi

Is there any method to change System. Exception. Message property in

derived
exception's constructor? I need runtime class' information to initialize this property, but it's readonly.

Thaks.



Nov 16 '05 #8
NO!

I would use the constructor As Jon identified:

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

If you need to "compute" the message to pass to "base (message)" I would
either use a static method to compute the message based to the base or I
would simply override the Message property.

Hope this helps
Jay
"Ivan A." <iv************@hotmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Hi

Thanks, I'll try that, but I think it will work!

I found another solution, in constructor of my exception I compute exception Message and then re-throw the same exception with this message string as
constructor parameter for new exception. So client gets new exception with
proper message property. Is this ok?
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:O1*************@TK2MSFTNGP10.phx.gbl...
Ivan,
In addition to passing it to the constructor, if you are creating a

derived
class, you can override the Message property.

Also remember that Exception.Message is intended for user display,
Exception.ToString includes "runtime class' information" by virtue of the stack trace property.

Hope this helps
Jay

"Ivan A." <iv************@hotmail.com> wrote in message
news:eF**************@tk2msftngp13.phx.gbl...
Hi

Is there any method to change System. Exception. Message property in

derived
exception's constructor? I need runtime class' information to initialize this property, but it's readonly.

Thaks.



Nov 16 '05 #9
Ivan A. <iv************@hotmail.com> wrote:
Thanx for reply, but base class constructor is called before I can do
something in my own constructor so this is not solution to my problem.


If you need to do processing before constructing the message, I suggest
you use a factory method instead - a static method which does the
processing and then creates the exception.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #10
Ivan A. <iv************@hotmail.com> wrote:
Thanx for reply, but base class constructor is called before I can do
something in my own constructor so this is not solution to my problem.


If you need to do processing before constructing the message, I suggest
you use a factory method instead - a static method which does the
processing and then creates the exception.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #11
I need runtime information of current class' instance so Message property
overloading is what I choosed...

--
/Ivan. ICQ: 121772779, MSN: iv************@hotmail.com

..
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Ivan A. <iv************@hotmail.com> wrote:
Thanx for reply, but base class constructor is called before I can do
something in my own constructor so this is not solution to my problem.


If you need to do processing before constructing the message, I suggest
you use a factory method instead - a static method which does the
processing and then creates the exception.

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

Nov 16 '05 #12

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

Similar topics

1
by: Matthias Ludwig | last post by:
I'm trying to create a directory on the web server with a vb.net code: .... Dim dirName As String = "w:\filepath\images" If Not Directory.Exists(dirName) Then...
1
by: Rafael | last post by:
Hi, I hope I can find some help for this problem IDE: Visual Studio.NET 2003 Developer Editio Language: C# Problem: "An unhandled exception of type 'System.NullReferenceException' occurred in...
2
by: Paul Gronka | last post by:
I've got a VB.NET windows application (written in VS .NET 2003) that makes a call to WMI for retrieving the MAC Address from the client's PC. It works on 4 out of the 5 PC's tested so far. All...
5
by: Vitling | last post by:
For no apparent reason, a NullReference exception is thrown in system.dll (System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback). Since I only get a disassembly from Visual Studio, it...
4
by: Bhavya Shah | last post by:
Hello, I am facing a very strange problem in my application. I have a form on which I select a path. I open the FolderBrowserDialog for path selection. Once the path is selected I press a button...
0
by: John.Luckowsky | last post by:
Hello all, I've moved my old ASP1.1 with WSE2.0 SP3 to ASP2.0 and have found strange error which raises spontaneously. Here is the stack trace: System.InvalidOperationException Message: The...
2
by: koredump | last post by:
Hi all, I have a windows app that makes some asyc calls to my webservice (WSE 3.0 with MTOM). exception gets thrown in the client win app. This exception is being thrown on another thread by a...
5
by: scheidel21 | last post by:
I am writting a DB front end in VB.NET 2003 I have a form that displays employee information it has a dataset loaded from the DB that also includes tables for lookup in some comboboxes that are...
2
by: pedrito | last post by:
I've got an app that downloads from several concurrent threads. Occasionally, I get an expcetion trying to read the HttpWebResponse stream... Sorry, the code isn't short, but I figured best to...
2
by: satnamsarai | last post by:
Using System.Net.Mail: Sometimes I get error 'failure sending mail. Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.' Not sure how...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
1
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...
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
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 ...

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.