One of the methods that I'm creating throws an exception. What's the clearest way of showing (either in code or comments) that my method could throw an exception and therefore a try{} and catch{} needs to be applied to my method.
Thanks!
One of the methods that I'm creating throws an exception. What's the clearest way of showing (either in code or comments) that my method could throw an exception and therefore a try{} and catch{} needs to be applied to my method.
Thanks!
In all of the MSDN documentation, every method shows what it may throw. I like this idea and thus in my comments I do something like:
// throws: MyDangerousError, StupidProgrammerError
If you want to go into more detail you can explain in what situations each error is thrown, often though the error name is enough to give users an Idea.
Sadly, clarity isn't the only issue. Otherwise, you could do this:
public void Method_MayThrowException() {
..
}
Since that is undesirable for other reasons, a comment that can be picked up by intellisense is likely to work the best.
Also, if you're open to add-ons or process modifications, you can read about Spec#. Or you could implement FxCop rules.