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

后端 未结 14 954
你的背包
你的背包 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:51

    In addition to the oft-repeated statement that "exceptions are for exceptional circumstances", here's an additionally clarifying rule I've come to like:

    If the user caused it, it's not exceptional.

    Exceptions are for system-side things (servers going down, resources being unavailable), not for the user doing odd things, because all users do odd things.

提交回复
热议问题