Home > Mobile >  Can't catch exception Firebase Realtime database
Can't catch exception Firebase Realtime database

Time:05-19

I am trying to throw a message when the password is less than 6 characters, but I can't catch the exception.

                  final email = _email.text;
                  final password = _password.text;
                  try {
                    final userCredential = await FirebaseAuth.instance
                        .createUserWithEmailAndPassword(
                        email: email,
                        password: password
                    );
                    
                    print(userCredential);
                  } on FirebaseAuthException catch (e) {
                      print(e.runtimeType);
                      print ('Password should be at least 6 characters long');
                      print(e);
                  }

I am trying to do it like this but the terminal keeps showing me that the Exception is Unhandled:

W/System  (18810): Ignoring header X-Firebase-Locale because its value was null.
    E/flutter (18810): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: [firebase_auth/weak-password] Password should be at least 6 characters
E/flutter (18810): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (18810): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18)
E/flutter (18810): <asynchronous suspension>
E/flutter (18810): #2      MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:377:43)
E/flutter (18810): <asynchronous suspension>
E/flutter (18810): #3      MethodChannelFirebaseAuth.createUserWithEmailAndPassword (package:firebase_auth_platform_interface/src/method_channel/method_channel_firebase_auth.dart:256:12)
E/flutter (18810): <asynchronous suspension>
E/flutter (18810): #4      FirebaseAuth.createUserWithEmailAndPassword (package:firebase_auth/src/firebase_auth.dart:238:7)
E/flutter (18810): <asynchronous suspension>
E/flutter (18810): #5      _RegisterViewState.build.<anonymous closure>.<anonymous closure> (package:flutter_firebase_example_7_04/main.dart:233:42)
E/flutter (18810): <asynchronous suspension>
E/flutter (18810):

I am using a realtime database with flutter.

What am I doing wrong?

CodePudding user response:

Try :

 on FirebaseAuthException catch (e) {
    print(e.code);
    print(e.message);
 }
  • Related