简体   繁体   English

未捕获Firebase异常

[英]Firebase Exception Not Being Caught

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. 我知道该异常需要是弱密码异常,但确实被捕获的异常是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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM