0
Reply

How do you know the method throws Exception or not via method API?

Administrator

Administrator

21 years ago
1.5k
How do you know a method throws Exception or not via method API? For example the method MyFn(string s) in the followin class: // Rethrowing exceptions: using System; class MyClass { public static void Main() { MyClass x = new MyClass(); try { string s = null; x.MyFn(s); } catch (Exception e) { Console.WriteLine("{0} Exception caught.", e); } } public void MyFn(string s) { if (s == null) throw(new ArgumentNullException()); } } Without looking at the actual method's body, how do we know whether or not the method throws what exception? I open the ildasm but no way I know what kind of Exception is thrown by the method MyFn(string s)? Unlike java, when method declared it says what exception(s) is(are) thrown, so via the API you know the method throws exception or not and what type of the exception as well. Is there any thing similar in C# beside the actual "throw" statement in the body? Any body has an idea how to know what exception(s) by not looking at the actual code which means via the API that normally what you get/given. Thanks