VS2008 (c#) 中有没有一种方法可以查看可能源自方法调用甚至整个 try-catch 块的所有可能的异常类型?

发布于 2024-09-02 21:03:16 字数 526 浏览 1 评论 0原文

VS2008 IDE 中的 c# 是否有一种方法可以查看可能源自方法调用甚至整个 try-catch 块的所有可能的异常类型?

我知道智能感知或对象浏览器告诉我此方法可以抛出这些类型的异常,但是除了每次都使用对象浏览器之外,还有其他方法吗?编码时更容易访问的东西?此外,我认为智能感知或对象浏览器除了读取 XML 代码注释之外没有做任何事情。

难道不应该扫描一个类的源代码并找到所有可以抛出的异常类型吗? (忘记基于方法输入的路径,只需扫描代码以查找异常类型)

我错了吗?扩展这个想法,您应该能够将鼠标悬停在“try”或“catch”关键字上,并显示一个工具提示,其中包含可以引发的所有类型的异常。

我的问题归结为,是否存在这样的 VS2008 附加组件? VS2010 可能会这样做吗?如果没有,您可以按照我描述的方式实现它,通过扫描类代码以查找抛出的异常类型,人们会发现它有用吗?异常会冒出来,因此您必须扫描每个方法调用的每一点代码,我想这可能是不切实际的,尽管我认为您可以第一次构建索引并以这种方式提高速度。

(这可能是一个很酷的小项目......)

Is there a way in VS2008 IDE for c# to see all the possible exception types that can possibly originate from a method call or even for an entire try-catch block?

I know that intellisense or the object browser tells me this method can throw these types of exceptions but is there another way than using the object browser everytime? Something more accessible when coding? Furthermore, I don't think intellisense or the object browser do anything more than read the XML code comments.

Shouldn't it be possible to scan a class's source and find all the exception types that can be thrown. (Forget path-ing based on method input, just scan the code for exception types)

Am I wrong? Extending this idea, you should be able to hover over the 'try' or 'catch' keywords and present a tooltip with all the types of exceptions that can be thrown.

My question boils down to, does a VS2008 add on like this exist? Does VS2010 do this perhaps? If not, could you implement it the way I've described, by scanning the class code for thrown exception types and would people find it useful. Exceptions bubble up so you have to scan every bit of code every method call, which I guess could be impractical, though I suppose you could build an index the first time and increase your speed that way.

(It might be a cool little project....)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吃不饱 2024-09-09 21:03:16

您正在寻找的是Red-Gate Exception Hunter

然而,Exception Hunter 是一个静态分析工具,它不可能告诉您每一段代码的所有信息。

例如,考虑到当今 IoC 容器的流行,您希望以下几行能够抛出什么样的异常:

var service = IoC.Resolve<ILogger>();
service.Log("Here");

这完全取决于正在解析的记录器的实际类型,它是否记录到文件?到数据库?到网络服务?到事件日志?

What you're looking for is Red-Gate Exception Hunter.

However, Exception Hunter is a static analysis tool, and there's no way it will be able to tell you everything for every piece of code there is.

For instance, given the prevalence of IoC containers today, what kind of exceptions would you expect the following lines to be able to throw:

var service = IoC.Resolve<ILogger>();
service.Log("Here");

It depends entirely on the actual type of logger being resolved, does it log to a file? to a database? to a network service? to the event log?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文