检查 xml 注释中的异常处理?
是否有任何 C# 代码分析工具可以验证 XML 注释中的异常是否在调用链的某个位置得到了处理?
假设只有需要专门处理的异常是 xml 注释的,这将是相当有用的。
Is there any C# code analysis tool that can verify if exceptions that are in the XML comments are handled somewhere up in the call chain?
Assuming only exceptions that need to be handled specifically are xml commented it would be rather useful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我还没有听说过任何 - 因为你不能使用反射来获取已编译程序集中的注释,所以我认为这是不可能的。编译器或代码分析工具可能可能检查任何抛出的(或下游?)异常是否在 XML 注释中得到了正确的注释,但仅此而已。
您可能对 Microsoft Research 的 Spec# 感兴趣。据项目现场介绍:
我想,这已经是你能得到的最接近的结果了。它将执行 Java 所做的事情:强制抛出异常的函数的调用者处理这些异常,或者在其元数据中声明它们自己传播/抛出这些异常,直到异常在某处得到处理。不过,我不知道 Spec# 是否允许您仅检查特定的异常类型。
I haven't heard of any - since you can't use reflection to get at the comments in a compiled assembly, I don't think this is possible. A compiler or code analysis tool could possibly check whether any thrown (or downstream?) exceptions are properly commented in the XML comments, but that's about it.
You might be interested in Spec# from Microsoft Research. According to the project site:
That, I think, is about as close as you're going to get. It will do what Java does: force callers of functions which throw exceptions to either handle those exceptions or state in their metadata that they themselves propagate/throw those exceptions, until the exception is handled somewhere. I don't know if Spec# will let you check only specific exception types, though.