Why are Exceptions not Checked in .NET?

前端 未结 10 1855
忘了有多久
忘了有多久 2020-11-27 03:36

I know Googling I can find an appropriate answer, but I prefer listening to your personal (and maybe technical) opinions.
What is the main reason of the differe

相关标签:
10条回答
  • 2020-11-27 04:21

    Additionally to the responses that were written already, not having checked exceptions helps you in many situations a lot. Checked exceptions make generics harder to implement and if you have read the closure proposals you will notice that every single closure proposal has to work around checked exceptions in a rather ugly way.

    0 讨论(0)
  • 2020-11-27 04:26

    The basic design philosophy of C# is that actually catching exceptions is rarely useful, whereas cleaning up resources in exceptional situations is quite important. I think it's fair to say that using (the IDisposable pattern) is their answer to checked exceptions. See [1] for more.

    1. http://www.artima.com/intv/handcuffs.html
    0 讨论(0)
  • 2020-11-27 04:26

    I went from Java to C# because of a job change. At first, I was a little concerned about the difference, but in practice, it hasn't made a difference.

    Maybe, it's because I come from C++, which has the exception declaration, but it's not commonly used. I write every single line of code as if it could throw -- always use using around Disposable and think about cleanup I should do in finally.

    In retrospect the propagation of the throws declaration in Java didn't really get me anything.

    I would like a way to say that a function definitely never throws -- I think that would be more useful.

    0 讨论(0)
  • 2020-11-27 04:27

    I sometimes miss checked exceptions in C#/.NET.

    I suppose besides Java no other notable platform has them. Maybe the .NET guys just went with the flow...

    0 讨论(0)
提交回复
热议问题