Flutter firebase handling exceptions

Viewed 2020

I am trying to catch the exceptions thrown by Firebase (from failed login) to flutter but I am having zero luck. .catcherror seems to print out the error but an exception is still crashing my code. I have found similar issues in other posts but no answers seem to help me, it's making my code unusable, thank you so much.

try {   signIn(typedemail, typedpassword).catchError((e) {
        print(e);
        print(e.message.toString()+"rrrrr");
        print(e.code);
        print(e.details);
      }); } 
on PlatformException catch (e)  { 
   print("on worked");//this doesnt work  } 
finally{
    print("finally");
} 

And I get this if I disable breaking on exceptions

D/FirebaseApp(11795): Notified 0 auth state listeners.

I/flutter (11795): PlatformException(exception, The email address is badly formatted., null)

I/flutter (11795): The email address is badly formatted.rrrrr

I/flutter (11795): exception

I/flutter (11795): null

1 Answers

You are trying to catch the exception twice; once when adding .catchError(...) and the second because you are surrounding it with a try-catch block.

I would suggest you only surround it with a try-catch block like this:

try {
      signIn(typedEmail, typedPassword);
} on PlatformException catch (error)  { 
      print("Error: " + error.toString());//Will work when you have errors
} finally {
    print("finally");
}

Related