在C#代码中找到未捕获的异常

编程入门 行业动态 更新时间:2024-10-27 10:32:34
本文介绍了在C#代码中找到未捕获的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想知道是否有一个工具可以使用静态代码分析在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#代码中找到未捕获的异常

本文发布于:2023-11-03 07:38:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554594.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   代码   中找到

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!