How to use Java-style throws keyword in C#?

前端 未结 10 2188
说谎
说谎 2020-11-27 04:39

In Java, the throws keyword allows for a method to declare that it will not handle an exception on its own, but rather throw it to the calling method.

Is there a sim

10条回答
  •  盖世英雄少女心
    2020-11-27 05:27

    Here is an answer to a similar question I just found on bytes.com:

    The short answer is no. There are no checked exceptions in C#. The designer of the language discusses this decision in this interview:

    http://www.artima.com/intv/handcuffs.html

    The nearest you can get is to use the tags in your XML documentation, and distribute NDoc generated docs with your code/assemblies so that other people can see which exceptions you throw (which is exactly what MS do in the MSDN documentation). You can't rely on the compiler to tell you about unhandled exceptions, however, like you may be used to in java.

提交回复
热议问题