Business Objects, Validation And Exceptions

后端 未结 18 884
自闭症患者
自闭症患者 2020-12-02 04:54

I’ve been reading a few questions and answers regarding exceptions and their use. Seems to be a strong opinion that exceptions should be raised only for exception, unhandled

18条回答
  •  抹茶落季
    2020-12-02 05:32

    If the input goes beyond the business rule implemented by the business object, I'd say it's a case not handled by the busines object. Therefore I'd throw an exception. Even though the setter would "handle" a 5 in your example, the business object won't.

    For more complex combinations of input, a vaildation method is required though, or else you'll end up with quite complex validations scattered about all over the place.

    In my opinion you'll have to decide which way to go depending on the complexity of the allowed/disallowed input.

提交回复
热议问题