How do I make visual studio show exceptions that a

2020-03-03 04:43发布

问题:

I was wondering about how I can make visual studio show the exceptions that any method may throw, not just the .NET Framework methods (I am using C#).

For example, here's a picture showing that when I hover over Console.WriteLine it says "Exceptions: System.IO.IOException".

However when I do that for any method I wrote it doesn't say what exception it throws, as shown in the following picture.

So how do I make visual studio show those exceptions? Do I need to add a specific attribute to the method?

回答1:

You can do this by adding an <exception> tag to the methods comment:

/// <summary>
/// Fooes this instance.
/// </summary>
/// <exception cref="ArgumentNullException">Yay for exception</exception>
public void Foo()
{ }