How to document thrown exceptions in c#/.net

Posted by Arnold Zokas on Stack Overflow See other posts from Stack Overflow or by Arnold Zokas
Published on 2009-01-20T13:39:28Z Indexed on 2010/06/02 10:33 UTC
Read the original article Hit count: 287

Filed under:
|
|
|

I am currently writing a small framework that will be used internally by other developers within the company.

I want to provide good Intellisense information, but I am not sure how to document thrown exceptions.

In the following example:

public void MyMethod1()
{
    MyMethod2();

    // also may throw InvalidOperationException
}

public void MyMethod2()
{
    System.IO.File.Open(somepath...); // this may throw FileNotFoundException

    // also may throw DivideByZeroException
}

I know the markup for documenting exceptions is:

/// <exception cref="SomeException">when things go wrong.</exception>

What I don't understand is how to document exceptions thrown by code called by MyMethod1()?

  • Should I document exceptions thrown by MyMethod2()
  • Should I document exceptions thrown by File.Open() ?

What would be the best way to document possible exceptions?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET