Is it a good or bad idea throwing Exceptions when validating data?

后端 未结 14 919
你的背包
你的背包 2020-12-07 16:27

When validating data, I\'ve gotten into a habit of doing the following:

Note: I don\'t really have individual booleans for each check. This is just

14条回答
  •  自闭症患者
    2020-12-07 16:54

    It depends - if you are expecting the data to be there and NOT having the data is unexpected, then throwing an exception is OK. Throwing an exception is very expensive (slow) but is the best way to handle unexpected circumstances.

提交回复
热议问题