Throwing ArgumentNullException

前端 未结 12 2240
名媛妹妹
名媛妹妹 2020-12-08 02:10

Suppose I have a method that takes an object of some kind as an argument. Now say that if this method is passed a null argument, it\'s a fatal error and an exception shoul

12条回答
  •  误落风尘
    2020-12-08 02:32

    I prefer the explicit exception, for these reasons:

    • If the method has more than one SomeClass argument it gives you the opportunity to say which one it is (everything else is available in the call stack).
    • What if you do something that may have a side effect before referencing x?

提交回复
热议问题