C#中明确定义抛出的异常是什么 [英] C# explicitly defining what exceptions are thrown
问题描述
在Java中,你明确地定义使用抛出关键字抛出什么异常。这样一来,任何人都调用你的方法知道抓什么。
In Java, you explicitly define what exceptions are thrown using the "throws" keyword. That way, anyone calling your method knows what to catch.
有什么在C#中?如果没有,我怎么知道抓什么异常,或者我怎么让别人知道抓什么异常?
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?
另外,如果我定义一个接口,在那里?一种方式说methodX()应该抛出错误此异常
Also, if I am defining an interface, is there a way to say "methodX() should throw this exception on error"?
推荐答案
有在C#中没有等价的:<一HREF =http://www.artima.com/intv/handcuffs.html>与检查异常
There is nothing equivalent in C#: The Trouble with Checked Exceptions
除了文档,还有就是麻烦没有办法来声明一个接口说methodX()应该抛出错误此异常。
Other than documentation, there is no way to declare an interface to say "methodX() should throw this exception on error".
这篇关于C#中明确定义抛出的异常是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!