0

UI code:

try {
    authService.signInWithEmailAndPassword(
        emailController.text, passwordController.text);
} catch (error) {
    print("ui rethrow");
}

Auth service code:

Future<User?> signInWithEmailAndPassword(
    String email,
    String password,) async {
        try {
            final credential = await _firebaseAuth.signInWithEmailAndPassword(
                email: email, password: password);
            return _userFromFirebase(credential.user);
        } catch (e) {
            print("service throw");
            rethrow;
        }
    }

I want to rethrow FirebaseAuthException from the authentication service to the UI, so I can give a user prompt with what went wrong, but the UI try-catch block doesn't catch the rethrown error.

Why doesn't my code work?

2
  • 1
    The caller doesn't catch the rethrown error because it doesn't await the returned Future. Commented Nov 9, 2021 at 4:43
  • Thank you so much, this solved my problem immediately! I'm new with Stack mechanics, can I highlight your answer, so others will know the answer? @jamesdlin Commented Nov 9, 2021 at 15:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.