Checking for handling of exceptions in xml comments?

334 views Asked by At

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.

1

There are 1 answers

0
Lars Kemmann On BEST ANSWER

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:

Spec# is an extension of the object-oriented language C#. It extends the type system to include non-null types and checked exceptions. It provides method contracts in the form of pre- and postconditions as well as object invariants.

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.