user3344394
user3344394

Reputation: 81

C# <exception > tag not showing

My constructor throws an exception. So I tried to add this line above it:

/// <exception cref="System.Exception">Thrown when...</exception>
public Person(int serial)
{
    if(....)
        throw new System.Exception();
}

When I write in Main: Person x = new Person(... it doesn't show what exception this might throw (in the tooltip box). The same problem occurs also with indexer and in properties, if I want to show it only for Set.

If I write it above regular other methods, it does show it.

Thanks in advance.
Liron.

Upvotes: 5

Views: 1427

Answers (1)

Slaf
Slaf

Reputation: 57

If you do not include the information in the XML comments for a method, property, or field, and in the correct format, Visual studio will not pick it up and display it. For a Constructor, the syntax would be:

/// <summary>
/// Create a person from a serial number
/// </summary>
/// <exception cref="ArgumentException">Thrown when serial number is outside valid     range</exception>
/// <param name="serial"></param>
public Person(int serial)
{
if (serial == 0)
    {
    throw new ArgumentException("Serial number cannot be zero");
    }
}

Unfortunately, even with this, exception information isn't displayed in Intellisense for constructors only in the generated documentation files!

[edit]Minor clarification[/edit]

Upvotes: 1

Related Questions