Why are Exceptions said to be so bad for Input Validation?

后端 未结 17 1416
萌比男神i
萌比男神i 2020-11-30 20:37

I understand that \"Exceptions are for exceptional cases\" [a], but besides just being repeated over and over again, I\'ve never found an actual reason for this fact.

<
17条回答
  •  我在风中等你
    2020-11-30 21:28

    1. Maintainability - Exceptions create odd code paths, not unlike GOTOs.
    2. Ease of Use (for other classes) - Other classes can trust that exceptions raised from your user input class are actual errors
    3. Performance - In most languages, an exception incurs a performance and memory usage penalty.
    4. Semantics - The meaning of words does matter. Bad input is not "exceptional".

提交回复
热议问题