C# Checked exceptions

后端 未结 3 1659
长情又很酷
长情又很酷 2021-01-07 05:47

One feature I really liked in Java that isn\'t in C# is checked exceptions. Is there any way to simulate (maybe via stylecop?) or turn on checked exceptions in Visual Studi

3条回答
  •  我在风中等你
    2021-01-07 06:17

    I bet you could use a tool like PostSharp to implement checked exceptions. Something like:

    [Throws(typeof(MyExpection))]
    public void Method()
    {
       throw new MyException();
    }
    

    Not sure if something like this already exists in PostSharp or some other AOP framework (and the reasons why the designers of .NET don't like checked exceptions still hold true) but I bet it would be possible to do.

提交回复
热议问题