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

后端 未结 17 1410
萌比男神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:20

    I agree with Mitch that that "Exceptions should not be used for normal control flow". I just want to add that from what I remember from my computer science classes, catching exceptions is expensive. I've never really tried to do benchmarks, but it would be interesting to compare performance between say, an if/else vs try/catch.

提交回复
热议问题