A custom exception with HelpLink and Source : Custom Exception « Language Basics « C# / CSharp Tutorial






using System;

public class CustomException : ApplicationException
{
  public CustomException(string Message) : base(Message)
  {
    this.HelpLink = "See the Readme.txt file";
    this.Source = "My Program";
  }
}

class MainClass
{
  public static void Main()
  {
    try
    {
      Console.WriteLine("Throwing a new CustomException object");
      throw new CustomException("My CustomException message");
    }
    catch (CustomException e)
    {
      Console.WriteLine("HelpLink = " + e.HelpLink);
      Console.WriteLine("Message = " + e.Message);
      Console.WriteLine("Source = " + e.Source);
      Console.WriteLine("StackTrace = " + e.StackTrace);
      Console.WriteLine("TargetSite = " + e.TargetSite);
    }
  }
}
Throwing a new CustomException object
HelpLink = See the Readme.txt file
Message = My CustomException message
Source = My Program
StackTrace =    at MainClass.Main()
TargetSite = Void Main()








1.24.Custom Exception
1.24.1.User-Defined Exception Classes
1.24.2.Use a custom Exception
1.24.3.Derived exceptions must appear before base class exceptions.
1.24.4.A custom exception with HelpLink and Source
1.24.5.Extends Exception
1.24.6.Create your own exception class based on Exception
1.24.7.CustomException is an application exception that supports remoting.