我想知道是否有一种工具可以使用静态代码分析在C#中查找未捕获的异常?基本上,我想选择一个methodA()并想要一个由methodA()抛出的所有异常以及由methodA()调用的所有方法的列表。我尝试了ReSharper + Agent Johnson和AtomineerUtils,但都失败了。
这是我的示例代码:
public class Rectangle
{
public int Width { get; set; }
public int Height { get; set; }
public int Area()
{
CheckProperties();
long x = Width * Height;
if (x > 10)
throw new ArgumentOutOfRangeException();
return (int) x;
}
private void CheckProperties()
{
if (Width < 0 || Height < 0)
throw new InvalidOperationException();
}
}
该工具应该能够(以任何形式)告诉我方法Area()将抛出
ArgumentOutOfRangeException
或InvalidOperationException.
最佳答案
我曾经在IDE中使用过R#插件-出色。坏主意是,它提示每个字符串.Format调用和可能引发的类似常见情况,但这不会引起问题。
自己决定是否值得:https://github.com/CSharpAnalyzers/ExceptionalReSharper
关于c# - 在C#代码中查找未捕获的异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7737926/