VardanMelkonyan
VardanMelkonyan

Reputation: 525

Flutter app is crashing although I wrote it in try catch block

I am using Firebase Auth for my app and for login and to handle errors I wrote it in a try-catch block, but when I enter an incorrect password the app just crashes and throws "PlatformException (PlatformException(ERROR_WRONG_PASSWORD, The password is invalid or the user does not have a password., null))" this error.

How can I fix this?

Here is the code, and the same is for registering users.

try {
    final newUser = await _auth.signInWithEmailAndPassword(email: email, password: password);
    if (newUser != null) {
        Navigator.pop(context);
    }
    } catch (e) {
        print(e);
    }

Upvotes: 2

Views: 2258

Answers (1)

Sludge
Sludge

Reputation: 7462

If the solution with VSCode's "All Exceptions" didn't work for you...

Keep in mind that the debug version may throw exceptions while the same code in a release version may not.

If you are sure that your code is failing within the try block and you are handling the catch correctly (like OP is), then try running your app with flutter run --release and check to see if it works.

Check this question/answer here for a bit more information: Flutter catching all unhandled exceptions

Upvotes: 3

Related Questions