Results 1 to 2 of 2

Thread: Problem in Custom Exception

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    india
    Posts
    273

    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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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;
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width