Should cstom exception type have serializable attribute?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I defined my own exception type as follows:

public class MyException: ApplicationException
{
public MyExceptionn() : base()
{
}

public MyException(string message) : base(message)
{
}

public MyException(
string message,
Exception innerException) : base(message, innerException)
{
}
}

I do not add any custom fields or properties.

Do I have to apply the [Serializable] custom attribute to the type?
Do I have to define special protected constructor which takes
SerializationInfo
and StreamingContext parameters?
 
Hi Dave,
I defined my own exception type as follows:

public class MyException: ApplicationException
{
public MyExceptionn() : base()
{
}

public MyException(string message) : base(message)
{
}

public MyException(
string message,
Exception innerException) : base(message, innerException)
{
}
}

I do not add any custom fields or properties.

Do I have to apply the [Serializable] custom attribute to the type?
Do I have to define special protected constructor which takes
SerializationInfo
and StreamingContext parameters?

Seems you've got the wrong group; you should use the C# one, this one is for
VC++.

As for your question, well, only if you want the exception to be
serializable (which is required if you expect to throw it across remoting
boundaries). It's a good practice, though.
 
Back
Top