Is there a throws keyword in C# like in Java? [duplicate]

纵饮孤独 提交于 2019-12-03 10:21:02

问题


Possible Duplicate:
how to use Java-style throws keyword in C#?

i have a function where an exception occurs say for example

private void functionName() throws Exception
{
   // some code that might throw an exception
}

thanks!


回答1:


No, because there are no checked exceptions in C#

If you are trying to document exceptions that are thrown, use the standard xml documentation

/// <exception cref="InvalidOperationException">Why it's thrown.</exception>



回答2:


No. There is no such construct in c#. But you can add the comment to your method like this /// <exception cref="Exception"></exception> and it will be visible in IntelliSense




回答3:


Unfortunately there isn't, and it can be a pain. The remedy is to be more careful with the exceptions that your code throws and how you handle errors.



来源:https://stackoverflow.com/questions/5726680/is-there-a-throws-keyword-in-c-sharp-like-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!