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. 11 3804
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.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com... 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.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
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.Messa ge is intended for user display,
Exception.ToStr ing 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******** ******@tk2msftn gp13.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.
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.Messa ge is intended for user display,
Exception.ToStr ing 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******** ******@tk2msftn gp13.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.
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******** *****@TK2MSFTNG P10.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.Messa ge is intended for user display, Exception.ToStr ing 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******** ******@tk2msftn gp13.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.
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******** *****@TK2MSFTNG P10.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.Messa ge is intended for user display, Exception.ToStr ing 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******** ******@tk2msftn gp13.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.
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******** *******@tk2msft ngp13.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******** *****@TK2MSFTNG P10.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.Messa ge is intended for user display, Exception.ToStr ing 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******** ******@tk2msftn gp13.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.
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******** *******@tk2msft ngp13.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******** *****@TK2MSFTNG P10.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.Messa ge is intended for user display, Exception.ToStr ing 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******** ******@tk2msftn gp13.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.
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.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
Directory.CreateDirectory(dirName)
Label1.Text = "Directory created"
Else
|
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 system.windows.forms.dll. Additional information: Object reference not set to an instance of an object.
Visual Studio's IDE is not allowing me to develop projects in C#... I've trying to create a simple Windows Forms project using Visual Studio.NET...
|
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 the workstations are DELLs running XP
SP1a with the 1.1 .NET Framework. The following line of code generates an
exception on the one PC:
Dim oMac As New
System.Management.ManagementClass("Win32_NetworkAdapterConfiguration")
The error it...
|
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 is almost
impossible to figure out what causes this. I've tried adding:
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler (SystemErrorHandler);
to my main method, and a handler function:
|
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 "Search" for
searching documents on that path. This search process runs in a separate
thread so that I can search for multiple paths simultaneously. I face
problem here. After starting the search for one path (that is starting one
thread), when I...
| |
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 XML Web service help page encountered an internal error.
Source: System.Web.Services
at
System.Web.Services.Protocols.WebServiceHandler.WriteException(Exception
|
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 class in the System.Web.Services
namespace and I have not been able to
catch it and dispose of it. I've tried placing try/catch blocks in
several places in my code, but this exception doesn't seem to bubble
up the stack.
|
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 bound to the employees table so
I load the combo boxes and then set the selectedText propertyt to bind to the
Employee table as only those listed are choosable, This works problem is now
my app it throwing the exception above within the...
|
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 provide the whole method.
This is run within its own thread. "Job" is a class that receives the
information about the downloaded pages. The exception happens on the read
where it says "EXCEPTION HERE"
|
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 to
fix this error.
I am able to send messages sometimes both other times randomly
following error appear
EXCEPTION:
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |