我想知道是否有一个工具可以使用静态代码分析在C#中找到未捕获的异常。基本上我想选择一个methodA()并且想要一个由methodA()抛出的所有异常以及methodA()所调用的所有方法的列表。我试过 ReSharper + 代理约翰逊和 AtomineerUtils 都不能完成这个简单的任务。 / p>
这是我的示例代码:
public class Rectangle { public int Width {get;组; } public int Height {get;组; } public int Area() { CheckProperties(); long x =宽度*高度; if(x> 10) throw new ArgumentOutOfRangeException(); return(int)x; private void CheckProperties() { if(Width< 0 || Height< 0) throw new InvalidOperationException(); } }该工具应该能够告诉我form)方法Area()将抛出 ArgumentOutOfRangeException 或 InvalidOperationException。
解决方案我在IDE中使用了一个R#addin - 超凡的。错误的想法,结果是它抱怨每一个字符串。格式调用和类似的常见情况,可能会抛出,但不会导致问题。
决定自己如果值得的话: github/CSharpAnalyzers/ExceptionalReSharper
I'm wondering if there is a tool to find uncaught exceptions in C# using static code analysis? Basically I want to select a methodA() and want a list of all exceptions thrown by methodA() and all methods called by methodA(). I tried ReSharper + Agent Johnson and AtomineerUtils, both fail this simple task.
Here's my example code:
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(); } }The tool should be able to tell me (in any form) that method Area() will throw ArgumentOutOfRangeException or InvalidOperationException.
解决方案I used an R# addin once that did that in the IDE - Exceptional. Bad idea, turns out that it complains about every single string.Format call and similar common cases that may indeed throw, but that won't cause issues.
Decide for yourself if it's worth it: github/CSharpAnalyzers/ExceptionalReSharper
更多推荐
在C#代码中找到未捕获的异常
发布评论