No, I would not have thought that the verification method should raise an exception.
This will create a little anti-pattern, since the client code calling this method will reasonably expect the exception to be thrown, and then it will need to catch the exception. Since it is generally recommended that exceptions not be used to control flow, why not just return a value indicating whether the check was successful or not. The client code can check the return value and act accordingly.
You, in fact, do the same thing as you, throwing an exception, but without the additional cost and bad semantics of the actual throwing of the exception.
Exceptions should be reserved for truly exceptional conditions, and not for the normal operation of the program. A failed check seems to me that this is a pretty normal state, which can be expected during the daily operation of the application. The call code will be easily processed and normal operation will continue. This is usually not the case with exceptions.
Cody Gray Jul 26 2018-11-11T00: 00Z
source share