Problem in Custom Exception
hi buddies, :)
I have written following code in Exception.cs file, now I want to use this custom exception in my project file. say webProject1.aspx.cs
can anybody guide me how do i use this in my project .
project Name is : WritingXML
Namespace is WritingXML
public class baseException : ApplicationException
{
public baseException(string strMessage) : base(strMessage)
{
}
public baseException() : base()
{
}
}
public class ProjectSegmentCreateArgumentException : baseException
{
public ProjectSegmentCreateArgumentException(string strMessage) : base(strMessage)
{
}
public ProjectSegmentCreateArgumentException() : base()
{
}
}
thanks in advancd
PPCC :cool:
Re: Problem in Custom Exception
The situation is exactly the same for any exception. You create an instance of the type, set whatever properties you require and then throw it. If you have a constructor that takes all the information your instance requires then you can do it in one line:
Code:
throw new Exception("An error has occurred.");
If you need to set properties seperately then you'll need to create the instance on a seperate line:
Code:
Exception e = new Exception();
e.Message = "An error has occurred";
throw e;