开发者

How do i throw an exception explicitly in c#?

In Java i can explicitly specify that a method throws an exception like:

public void read() throws IOException{}

What is the c# equivalent of this?

What are the best practices for throwing custom exceptions?

I have made them seriali开发者_如何学Pythonzable and provided a streaming context also .


What you're referring to is the actual documentation of code that throws exceptions.

Read this thread that discusses this question: How to document thrown exceptions


The topic in MSDN called Exceptions and Exception Handling covers Creating and Throwing Exceptions in detail.

However, exception specifications are not part of the C# language like they are in Java. You must rely on documentation to tell the user of your API what exceptions may be thrown. You cannot force a user to handle an exception, or document it in code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜