If one has the following code:
data.SaveChanges();
(data is an ObjectContext)
The MSDN doc has listed the OptimisticConcurrencyException as thrown. That’s fine but I known that a UpdateException can also be thrown (and possibly others too). How can I know which exceptions a method can throw?
I do not want to catch Exception as I only want to catch exceptions which I know I can handle in some way.
This is generally speaking – not just for the example above. There must be some way of knowing which exception a ‘built-in’ .NET method is throwing.
That’s not a “native” method; it’s an ordinary method that happens to be written by Microsoft rather than you.
Actual native methods cannot throw managed exceptions (although COM interop will convert things to managed exceptions)
Unlike Java, C# does not have exception specifications, so there is no inherent way of knowing what exceptions a method will throw.
Your only options are the documentation or a decompiler.