Click to See Complete Forum and Search --> : Should custom exception type have serializable attribute?


Bobby2001
October 14th, 2004, 09:49 AM
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?

TheCPUWizard
October 14th, 2004, 10:50 AM
...Do I Have To...


No, you dont. Serialization is needed when you want be be able to pass the object [e.g. for use in remoting] or if you need to persist the object. If the exception is going to be thrown and caught within a process, this is typically not necessary.