Should I throw on null parameters in private/internal methods?

前端 未结 7 1883
逝去的感伤
逝去的感伤 2021-02-05 02:56

I\'m writing a library that has several public classes and methods, as well as several private or internal classes and methods that the library itself uses.

In the publi

7条回答
  •  粉色の甜心
    2021-02-05 03:21

    In my opinion you should ALWAYS check for "invalid" data - independent whether it is a private or public method.

    Looked from the other way... why should you be able to work with something invalid just because the method is private? Doesn't make sense, right? Always try to use defensive programming and you will be happier in life ;-)

提交回复
热议问题