George George

George George

  • NA
  • 778
  • 0

Exception Constructor

Nov 14 2008 8:18 AM

Hello everyone,


For the exception constructor,

Exception Constructor (SerializationInfo, StreamingContext)

http://msdn.microsoft.com/en-us/library/tz6bzkbf.aspx

I have two questions,

1. I saw some code defines it as public and some other code defines it as protected. What are the different purposes of different definitions?

2. I saw some code which defines a new exception type derives from System.Exception, and implements this contructor, but the implementation code is just call the base class constructor, and at the same time, the class is marked with Serializable tag. Like this.

I think such type of implementation is useless since the implementation of constructor is empty (just call base class contructor and the class is already marked with Serializable tag), so it is system default behavior and it should be ok to just mark it with Serializable tag to achieve the same effect.

Any comments?

[Code]
[Serializable]
public class MyExceptionClass : Exception
{
    public MyExceptionClass (string errorMessage)
    {

    }

    public MyExceptionClass (SerializationInfo info, StreamingContext context) : base (nfo, context)
 {

 }
}
[/Code]


thanks in advance,
George