Setting the HelpLink Property when You Throw an Exception

You can use the HelpLink property of an Exception object to point to a web page that might have information that is relevant to the exception that you are throwing.  Exception handling code could then use the property to navigate to a web page.
In the code below, we throw an exception if the caller asks a Dog to bark too many times.
1
2
3
4
5
6
7
8
9
10
11
public void Bark(int numTimes)
{
    if (numTimes > 12)
    {
        Exception xx = new Exception("Too much barking");
        xx.HelpLink = "<span class="skimlinks-unlinked">http://www.ehow.com/how_4510663_stop-dog-from-barking-much.html</span>";
        throw xx;
    }
 
    Console.WriteLine(string.Format("{0}: Woof", Name));
}
In our exception handler, we then navigate to a web page if HelpLink has been set.
1
2
3
4
5
6
7
8
9
10
11
try
{
    Dog d1 = new Dog("Jack", 15);
    d1.Bark(1000);
}
catch (Exception xx)
{
    Console.WriteLine(xx);
    if (xx.HelpLink != null)
        <span class="skimlinks-unlinked">Process.Start(xx.HelpLink</span>);
}


886-001