Why must a type thrown or caught derive from System.Exception

前端 未结 6 1015
独厮守ぢ
独厮守ぢ 2021-02-12 09:44

So just out of curiosity I wanted to see what was special about the exception class that allowed it to be used with the keyword Throw while a standard class is not.

6条回答
  •  无人及你
    2021-02-12 09:56

    It is an arbitrary choice of the designers of the CLS. Presumably they made this choice for reasons of consistency. C# follows the CLS; the requirement is enforced by the compiler for this reason, not for any technical reason related to the implementation of the Exception type.

    The CLI can actually throw any object. See http://jilc.sourceforge.net/ecma_p3_cil.shtml#_Toc524462405.

提交回复
热议问题