可能的复制品: 如何在 C # 中使用 Java 风格的 throw 关键字
我有一个发生异常的函数 比如说
private void functionName() throws Exception { // some code that might throw an exception }
谢谢!
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
/// <exception cref="Exception"></exception>
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>
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.