This is my existing code.
mAuth.createUserWithEmailAndPassword(registration.getEmail(), registration.getPassword())
.addOnSuccessListener(this, authResult -> {
Log.i("exception0", "here0");
})
.addOnFailureListener(this, exception -> {
if (exception instanceof FirebaseAuthWeakPasswordException) {
Log.i("exception1", "here");
} else if (exception instanceof FirebaseAuthInvalidCredentialsException) {
Log.i("exception2", "here1");
} else if (exception instanceof FirebaseAuthUserCollisionException) {
Log.i("exception3", "here2");
} else if (exception instanceof FirebaseAuthInvalidUserException) {
Log.i("exception4", "here3");
} else if (exception instanceof FirebaseAuthException) {
Log.i("exception5", "here4");
} else if (exception instanceof FirebaseException) {
FirebaseException firebaseException = (FirebaseException) exception;
Log.i("exception6", "here5" + firebaseException.getMessage());
} else {
Log.i("exception7", "here6");
}
});
I know that the exception needs to be a weak password exception but the exception that does get caught is a FirebaseException.
I even tried the following code
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());
}
}
But it would always catch the last generalised exception and not a specific one.
尝试一下:
if(e.getClass().equals(FirebaseAuthWeakPasswordException.class))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.