It is easy to find opinions that consider it bad practice to use exceptions for non-exceptional events, here is an example:
Definitely not exceptions. A failed login is hardly an "exceptional" case and it just a normal course of logic for the application. If you use an exception then you'll always have to wrap logging in with an exception handler for no other reason than to handle the case of a failed login. That seems like the very definition of using exceptions for logic flow, which isn't right.
https://stackoverflow.com/a/22807812/1283776
It is equally easy to find opinions that consider it good practice to reject promises for non-exceptional events, here is an example:
When you have an asynchronous operation with a promise interface, one would usually reject the Promise with an Error object as the reject reason to signify an error. That's the core design theory of promises.
https://stackoverflow.com/a/56918433/1283776
Why does the general community consider it bad practice to throw errors for non-exceptional events and reject promises for the same? The reason for my confusion is that these to error passing constructs seem very similar to me. Here is how I would need to handle them in client code:
Login is synchronous and throws an error if unsuccessful:
try {
login(credentials)
// get token
} catch (err) {
// print: unable to login
}
Login is asynchronous and rejects a promise if unsuccessful:
try {
await login(credentials)
// get token
} catch (err) {
// print: unable to login
}