Java 未捕获Firebase异常
这是我现有的代码Java 未捕获Firebase异常,java,android,exception,firebase,firebase-authentication,Java,Android,Exception,Firebase,Firebase Authentication,这是我现有的代码 mAuth.createUserWithEmailAndPassword(registration.getEmail(), registration.getPassword()) .addOnSuccessListener(this, authResult -> { Log.i("exception0", "here0"); })
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");
}
});
我知道异常需要是弱密码异常,但捕获的异常是FirebaseException
我甚至尝试了以下代码
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());
}
}
但它总是捕获最后一个通用异常,而不是特定异常。尝试以下操作:
if(e.getClass().equals(FirebaseAuthWeakPasswordException.class))
如果在
here5
分支中记录exception.getClass().getName()
,会得到什么?