Should a business rule violation throw an exception?

后端 未结 14 650
误落风尘
误落风尘 2021-02-04 04:18

Should a business rule violation throw an exception?

14条回答
  •  一生所求
    2021-02-04 05:08

    It really depends on what it is and where it is.

    If it's some data coming from the user then as levand said it's a matter of validation. Validation can turn up both successful and failed, both are expected options with clear further action scenarios.

    If it's something like method execution errors it could be a better idea to throw an exception and stop right there before more harm is done (such as producing inconsistencies in the database).

    It is often a matter of perspective and your application design.

提交回复
热议问题