How to Document that a Method Can Throw an Exception

You can use XML Documentation to document the fact that a method can throw an exception.  You use the Exception tag to indicate the type of exception that can be thrown.  You can also provide a comment related to the exception, which will show up in an XML Documentation file that you generate.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/// <summary>
/// Print somebody's name
/// </summary>
/// <param name="name">Name to be printed</param>
/// <exception cref="ApplicationException">Will throw exception if name is Mortimer</exception>
/// <exception cref="JustBecauseException">I throw this exception on Tuesdays</exception>
static void PrintMyName(string name)
{
    if (name.ToLower().Equals("mortimer"))
        throw new ApplicationException("I don't like the name Mortimer");
 
    if (<span class="skimlinks-unlinked">DateTime.Now.DayOfWeek</span> == DayOfWeek.Tuesday)
        throw new JustBecauseException("Tuesday is my day off");
 
    Console.WriteLine(string.Format("Your name is {0}", name));
}
Intellisense will now include a list of the exceptions that might be thrown, when displaying the method’s name.
913-001

If you generate a XML Documentation file, it will also include this information.
913-002