Reputation: 1873
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
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
Reputation: 13591
I think Resharper does it if my memory serves correctly. Take a look at Pex, it might interest you too.
Upvotes: 0
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