Click here to Skip to main content
16,003,224 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My constructor throws an exception. So I tried to add this line above it:

/// <exception cref="System.Exception">Thrown when...
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
Posted
Comments
Raul Iloc 24-Mar-14 7:37am    
Why did you UnDo the Acceptance of my solution, because it is solving your problem (I am have using this in many projects)?

You have to comment your constructor like in the next example:
C#
/// <summary>
/// Your class comment...
/// </summary>
/// <exception cref="AccessViolationException">Your comment...</exception>
public Person(int serial)
{
...
}
 
Share this answer
 
Comments
shahed.sohail 24-Mar-14 8:20am    
Sorry Raul. Maybe by mistake i did.. sorry for it. cheers
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:
C#
/// <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]
 
Share this answer
 
v2
Comments
shahed.sohail 24-Mar-14 6:50am    
Thanks all friends

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900