2017-01-29 3 views
0

Это мой существующий код.Исключение Firebase Не будучи пойманным

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()); 
} 
} 

Но он всегда будет поймать последний обобщенную исключение, а не конкретный один.

+0

Что вы получите, если вы войдете 'exception.getClass() GetName()' в 'здесь 5' ветвь.? –

ответ

0

Попытка это:

if(e.getClass().equals(FirebaseAuthWeakPasswordException.class))