473,395 Members | 1,541 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,395 software developers and data experts.

Exception class with additional parameter

I would like to create a new exception class with an additional
parameter, something like this:

public class MyException: Exception
{
private String field = "";
public void MyException(String Message, String Field)
{
this.field = Field;
...
}
}

How do I go about this? In particular, I want the Message parameter to
have the normal interpretation.

Jamie O
Nov 16 '05 #1
5 1326
Jamie,

JO> I would like to create a new exception class with an additional
JO> parameter [...]

using System;

public class MyException : Exception {
private string field;

public MyException(string message, string field)
: base(message) {
this.field = field;
}
}

HTH,

Stefan
Nov 16 '05 #2
Hi,

Use the base class's constructor:

class MyException : Exception
{
public void MyException(string message, string field) : base (message)
{
...
}
}

"Jamie Oglethorpe" <jamieoATiafrica.com> wrote in message
news:77********************************@4ax.com...
I would like to create a new exception class with an additional
parameter, something like this:

public class MyException: Exception
{
private String field = "";
public void MyException(String Message, String Field)
{
this.field = Field;
....
}
}

How do I go about this? In particular, I want the Message parameter to
have the normal interpretation.

Jamie O
Nov 16 '05 #3
<Jamie Oglethorpe <jamieoATiafrica.com>> wrote:
I would like to create a new exception class with an additional
parameter, something like this:

public class MyException: Exception
{
private String field = "";
public void MyException(String Message, String Field)
{
this.field = Field;
...
}
}

How do I go about this? In particular, I want the Message parameter to
have the normal interpretation.


Then you need to call the appropriate base constructor. For instance:

public MyException (string message, string field) : base (message)
{
this.field = field;
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Jamie,
The other showed how to do it, the following article gives some guidelines
to follow when you do create custom exceptions:

http://msdn.microsoft.com/library/de...rp08162001.asp

Hope this helps
Jay

"Jamie Oglethorpe" <jamieoATiafrica.com> wrote in message
news:77********************************@4ax.com...
I would like to create a new exception class with an additional
parameter, something like this:

public class MyException: Exception
{
private String field = "";
public void MyException(String Message, String Field)
{
this.field = Field;
...
}
}

How do I go about this? In particular, I want the Message parameter to
have the normal interpretation.

Jamie O

Nov 16 '05 #5
Thanks guys. I knew there had to be some elegant way of doing this.
Nov 16 '05 #6

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

Similar topics

4
by: Nicolas Fleury | last post by:
Hi, I've made a small utility to re-raise an exception with the same stack as before with additional information in it. Since I want to keep the same exception type and that some types have very...
44
by: craig | last post by:
I am wondering if there are some best practices for determining a strategy for using try/catch blocks within an application. My current thoughts are: 1. The code the initiates any high-level...
4
by: andrewcw | last post by:
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...
1
by: morrisqueto | last post by:
Hello, One of my websites just started sending a new rare error. The site has been working for almost 2 years without trouble, but today morning started giving away this error in all my views. ...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...

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.