Why should I use asserts?

后端 未结 19 1904
遇见更好的自我
遇见更好的自我 2020-12-12 13:47

I never got the idea of asserts -- why should you ever use them?

I mean, let\'s say I were a formula driver and all the asserts were things like security belt, helm

相关标签:
19条回答
  • 2020-12-12 14:36

    Assertion should be used for anticipating error in the way a programmer is using an API/function/class/whatever. These bugs need to be fixed quickly at debug time.

    For everything else, throw an exception.

    0 讨论(0)
提交回复
热议问题