Using Firebase, how do I catch a specific exception and tell the user gracefully about it? E.g :
FirebaseAuthInvalidCredentialsException: The email ad
You can throw the Exception returned by task.getException
inside a try block and catch each type of Exception that may be thrown by the method you are using.
Here is an example from the OnCompleteListener
for the createUserWithEmailAndPassword
method.
if(!task.isSuccessful()) {
try {
throw task.getException();
} catch(FirebaseAuthWeakPasswordException e) {
mTxtPassword.setError(getString(R.string.error_weak_password));
mTxtPassword.requestFocus();
} catch(FirebaseAuthInvalidCredentialsException e) {
mTxtEmail.setError(getString(R.string.error_invalid_email));
mTxtEmail.requestFocus();
} catch(FirebaseAuthUserCollisionException e) {
mTxtEmail.setError(getString(R.string.error_user_exists));
mTxtEmail.requestFocus();
} catch(Exception e) {
Log.e(TAG, e.getMessage());
}
}