Programming Java in Eclipse, I'm used to having to deal with exceptions. In C# with VisualStudio it seems I can not say "throws exception" on a method... After a lot of coding I found lots of exceptions, and had to catch them as I found them during testing. I'd like to be forced to handling them, so that VisualStudio can say that here you need a catch or I'm not going to let you go on :) Is this possible?
Thanks
No. C# doesn't force you to handle exceptions. This was a concious design decision on the part of the language designers.
For details on why, see The Trouble With Checked Exceptions, where Anders Hejlsberg discusses why they aren't part of C#.
No there are no checked exceptions in C#. And the reasons are pretty simple:
1) they tend not to achieve there intended purpose because not every follows the recommended practice of either handling them explicitly or passing them up the chain. Instead what happens is that they are "eaten" by developers in the middle of the dev stack.
2) since they are naturally part of documentation rather than executable code, they should go into documentation and not clutter the code surface
3) C#/Framework documentation in dev tools are the ideal place for such documentation. Play around with the visual studio Object browser, browse to the method and you will see them mentioned in the lower pane.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With