Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a problem handling firebase_auth errors, every way when I try signIn, I get some errors, although I have used try and catch. Earlier I have turned off the uncaught exceptions option in vsc but I would like to also get the error message from catch

sample errors message

Future<Either<LoginFailure, LoginSucces>> signInWithEmail(
    {String email, String password}) async {
  try {
    await _auth.signInWithEmailAndPassword(email: email, password: password);
  } on PlatformException catch (e) {
    return Left(LoginFailure(errorMessage: '${e.toString()}'));
  }
}
question from:https://stackoverflow.com/questions/65644170/flutter-try-and-catch-dontt-handle-firebase-auth-errors

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
301 views
Welcome To Ask or Share your Answers For Others

1 Answer

This code only catch PlatformException as written.

  try {
    await _auth.signInWithEmailAndPassword(email: email, password: password);
  } on PlatformException catch (e) {
    return Left(LoginFailure(errorMessage: '${e.toString()}'));
  }

you can catch all exception like this.

  try {
    await _auth.signInWithEmailAndPassword(email: email, password: password);
  } catch (e) {
    return Left(LoginFailure(errorMessage: '${e.toString()}'));
  }

also you can do this

  try {
    await _auth.signInWithEmailAndPassword(email: email, password: password);
  } on PlatformException catch (e) {
    return Left(LoginFailure(errorMessage: '${e.toString()}'));
  } catch(e) {
    // All other than Platform exception will drop here 
    print(e);
  }


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...