我有以下 FooClass
。共有三种方法,其中两种可以抛出 exception
。
如果仅在 HasException
方法中声明,则可以抛出 exception
。
当您有大型项目时,您可能会忘记在摘要中描述异常
。
如果我忘记声明一个exception
,是否可以扫描解决方案?在我的示例中,缺少四个 exceptions
(声明)。
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");
}
}
工具提示
这应该是如何描述该方法的示例
/// <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");
}
最佳答案
执行此操作的一种方法(不是唯一的方法)是使用名为“Exceptional”的 Resharper 扩展。转到 Resharper > Extension manager > 搜索“Exceptional”,安装并重新启动 Visual Studio。之后,所有可能抛出异常但未记录的地方都将带有下划线,并且使用 alt-enter 您将能够自动创建异常文档模板。对于您的示例,它会找到您提到的所有情况甚至更多(构造函数本身,它也可以抛出所有异常)。
关于c# - Visual Studio |如果忘记在摘要中声明异常则通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47197234/