6

I'm from an Android background and when looking up a method in the Android developers reference, the information usually includes what exceptions the method can throw (as well as the parameters the method takes in and its return type). I've had a browse of some classes in the MSDN library and this doesn't seem to be the case here. So how, when developing, can I determine what exceptions a method can throw (if it throws any exceptions)?

A concrete example is the DataContext.SubmitChanges() method (MSDN link), which can throw an SqlCeException exception. It seems there's no way of picking up on this unless it's encountered accidentally at run-time.

Adil Hussain
  • 30,049
  • 21
  • 112
  • 147

2 Answers2

3

.NET is a bit different than java in exceptions. There is no throws syntax, where you have to declare what types of exceptions can be thrown from the method. Every method can possibly throw any kind of exception. That's why not always MSDN documentation contains that kind of data.

When you can't find list of possible exceptions on MSDN pages you can search/ask about it on sites like stackoverflow (eg. for DataContext.SubmitChanges()) or just test your app and try to generate the exception to check what type it is.

Community
  • 1
  • 1
MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263
1

There is no equivalent to the throws keyword in .net, but you can tell your user what exceptions you know your method may throw in your doc-comments (C# equivalent to java doc)

BenCamps
  • 1,694
  • 15
  • 25