VisualStudio | Notify if forgotten to declare an Exception in the summary

Viewed 62

I have the following FooClass. There are three methods where two of them can throw an exception. If have only declared in the HasException method that there can be an exception thrown. When you have large projects it can be possible that you forget to describe the exceptions in the summary.

It is possible to scan the solution if I have forgotten to declare an exception? In my example are four exceptions (declarations) missing.

public class FooClass
{
    public FooClass()
    {
        HasException();

        HasNoException();

        HasChildException();
    }

    /// <summary>
    /// This method does not throw an <see cref="Exception"/>.
    /// </summary>
    public void HasNoException()
    {

    }

    /// <summary>
    /// This method is throwing an <see cref="Exception"/>.
    /// </summary>
    /// <exception cref="Exception">Is immediately thrown.</exception>
    public void HasException()
    {
        throw new Exception();
    }

    /// <summary>
    /// This method can throwing an <see cref="Exception"/> from a method it calls.
    /// </summary>
    public void HasChildException()
    {
        //throws an exception
        HasException();

        //throws also an exception
        int.Parse("foo");
    }
}

ToolTips

hasexception parse

This should be an example how the method should be described

/// <summary>
/// This method can throwing an <see cref="Exception"/> from a method it calls.
/// </summary>
/// <exception cref="Exception"></exception>
/// <exception cref="ArgumentNullException"></exception>
/// <exception cref="FormatException"></exception>
/// <exception cref="OverflowException"></exception>
public void HasChildException()
{
    //throws an exception
    HasException();

    //throws also an exception
    int.Parse("foo");
}

preview

1 Answers

One way to do this (not the only one) is to use Resharper extension named "Exceptional". Go to Resharper > Extension manager > search for "Exceptional", install and restart Visual Studio. After that all places where exception might be thrown which is not documented will be underlined and with alt-enter you will be able to automatically create exception documentation template. For your example it finds all cases you mentioned and even more (constructor itself, which can also throw all thsoe exceptions).

Related