zxcvbnm
zxcvbnm

Reputation: 1873

C#: Does Visual Studio 2008 have a tool to show which Exceptions could be raised by a piece of code?

For example, if I'm opening a file, I know a FileNotFoundException might happen, or if I'm converting a String to double, a FormatException may happen. Obviously, if a method does both, both can be raised.

Is there a way to quickly see all possible exceptions raised by a method though? Keeping track of it myself seems error prone.

Upvotes: 26

Views: 1807

Answers (5)

Ian Boyd
Ian Boyd

Reputation: 256999

The Agent Johnson pklugin to ReSharper

Upvotes: 1

rerun
rerun

Reputation: 25505

There is no concrete way to find all exceptions a piece of code unless you have a way of running every possible branch in whatever piece of code you are exercising. While tools may be able to evaluate what are likely errors are to occur you still are going to run into situations which these tools will will not catch. While i'm not saying there is no reason to run them you still have to code is such a way to handle errors your tool may not catch. I have seen tools like this used in place of good testing and coding practices.

Also some times exceptions are good things. Some of the hardest and greatest impact errors I have ever found is due to developers handling errors in such a way that program continues but is no longer in a state that any future called code is expecting. just my .02

Upvotes: 0

Perpetualcoder
Perpetualcoder

Reputation: 13591

I think Resharper does it if my memory serves correctly. Take a look at Pex, it might interest you too.

Upvotes: 0

Christopher Tarquini
Christopher Tarquini

Reputation: 11342

If memory serves me correctly if the intellisense tool tip should have a list of exceptions the method can throw. You can also open a browser tab in visual studio pointing to MSDN like so: http://msdn.microsoft.com/en-us/library/b9skfh7s.aspx#ddueExceptionsToggle

Upvotes: 1

taylonr
taylonr

Reputation: 10790

It's not built into VS. There are 3rd party tools, though, like Redgate's exception hunter.

Edit I'm not employed by RG, but I am a fan of their products. I've tried this particular one, but we ended up not buying it.

Upvotes: 10

Related Questions