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

前端 未结 8 1638
滥情空心
滥情空心 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:46

    Trying to answer "..thankfully 'ex' is not null, but could it ever be?":

    Since we arguably cannot throw exceptions that is null, a catch clause will also never have to catch an exception that is null. Thus, ex could never be null.

    I see now that this question has in fact already been asked.

提交回复
热议问题