查找在C#code未捕获的异常 [英] Find uncaught exceptions in C# code

查看:142
本文介绍了查找在C#code未捕获的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有工具来查找在C#中捕获的异常使用静态code分析?基本上,我想选择的methodA(),并希望抛出的methodA所有异常(),并调用了methodA所有方法()的列表。我想 ReSharper的 +的代理约翰逊 AtomineerUtils ,均不能这种简单的任务。

下面是我的例子code:

 公共类矩形
{
    公众诠释宽度{获得;组; }
    公众诠释高度{获得;组; }

    公众诠释面积()
    {
        CheckProperties();
        长×=宽*高;
        如果(X→10)
            抛出新ArgumentOutOfRangeException();
        返程(INT)×;
    }

    私人无效CheckProperties()
    {
        如果(宽℃,||高度℃下)
            抛出新的InvalidOperationException异常();
    }
}
 

该工具应能告诉我(任何形式),该方法面积()会抛出 ArgumentOutOfRangeException InvalidOperationException异常。

解决方案

我使用的R#插件一旦这样做,

在IDE - 卓越。坏主意,事实证明,它抱怨每一个的String.Format通话以及可能确实抛出类似常见的情况,但不会造成问题。

自己决定,如果它是值得的: HTTP://exceptionalplugin.$c$cplex.com

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: http://exceptionalplugin.codeplex.com

这篇关于查找在C#code未捕获的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆