When to throw an exception?

后端 未结 30 1975
后悔当初
后悔当初 2020-11-21 23:48

I have exceptions created for every condition that my application does not expect. UserNameNotValidException, PasswordNotCorrectException etc.

30条回答
  •  你的背包
    2020-11-22 00:40

    Exceptions are a somewhat costly effect, if for example you have a user that provides an invalid password, it is typically a better idea to pass back a failure flag, or some other indicator that it is invalid.

    This is due to the way that exceptions are handled, true bad input, and unique critical stop items should be exceptions, but not failed login info.

提交回复
热议问题