Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# explicitly defining what exceptions are thrown

In Java, you explicitly define what exceptions are thrown using the "throws" keyword. That way, anyone calling your method knows what to catch.

Is there something in C#? If not, how do I know what exceptions to catch, or how do I let others know what exceptions to catch?

Also, if I am defining an interface, is there a way to say "methodX() should throw this exception on error"?

like image 569
Andy Hin Avatar asked Nov 03 '10 14:11

Andy Hin


1 Answers

There is nothing equivalent in C#: The Trouble with Checked Exceptions

Other than documentation, there is no way to declare an interface to say "methodX() should throw this exception on error".

like image 184
Mitch Wheat Avatar answered Sep 19 '22 03:09

Mitch Wheat