Why does C# allow you to 'throw null'?

前端 未结 8 1627
滥情空心
滥情空心 2020-12-04 14:03

While writing some particularly complex exception handling code, someone asked, don\'t you need to make sure that your exception object isn\'t null? And I said, of course n

8条回答
  •  失恋的感觉
    2020-12-04 14:50

    Taken from here:

    If you use this expression in your C# code it will throw a NullReferenceException. That is because the throw-statement needs an object of type Exception as its single parameter. But this very object is null in my example.

提交回复
热议问题