The nature of the exceptions is that they should be explicitly ignored. Suppose you have this function:
bool authenticate ( String username, String password ) { if ( invalid_password(password) ) { return (false); }
Now think that this is part of a server, and that the server is running in a very privileged context. If the calling code (the one that performs the authorization) has some error in it, it may inadvertently allow users to perform actions that are usually not allowed.
I would write the following function:
void authenticate ( String username, String password ) { if ( invalid_password(password) ) { throw new LoginFailed(); }
Please note that this is a purely protective approach to programming, and this is my preference in this context. Thus, a login error will most likely prevent the operation from continuing.
source share