Exception class with additional parameter

  • Thread starter Thread starter Jamie Oglethorpe
  • Start date Start date
J

Jamie Oglethorpe

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
 
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
 
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
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
 
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;
}
 
Back
Top