Exception.
2.if there is no scenario for programmers needing the class
then do not create a exception class
3.throw the exception most specifically
4.if you use innerExceptions then good.
5.throw ArgumentException or it's subclass when false arguments
have been passed.
following are the codes for creating a exception-TestException-
using System;
public class TestException : Exception
{
//Constructors. It is recommended to use all
public TestException() : base() { }
public TestException(string testMessage) : base(testMessage) { }
public TestException(string testMessage, Exception e) :
base(testMessage, e) { }
//create needed properties for extra error information.
private string strExtraInformation;
public string ExtraErrorInformation{
get{return strExtraInformation;}
set{strExtraInformation = value;}}
public class TestTestException{
public static void Main(){
try{TestException obj;
obj = new TestException("My Exception Occured");
obj.ExtraErrorInformation = "Extra Error Info";
throw obj;} catch (TestException e){
Console.Write(String.Concat(e.StackTrace, e.Message));
Console.Write(e.ExtraErrorInformation);}
Console.Read();}}
}
code summary::
in the above exception class i created is come from the base
System.Exception class.first all constructors called the
constructors of base class.I also created property-
ExtraErroInfo to store extra error info.