Home > Enterprise >  Flutter try catch error in exception when passing e.string
Flutter try catch error in exception when passing e.string

Time:07-12

Error is

The getter 'errormessage' isn't defined for the type 'Object'. Try importing the library that defines 'errormessage', correcting the name to the name of an existing getter, or defining a getter or field named 'errormessage'

Here is my Code :

     User user = (await auth.signInWithEmailAndPassword(
         email: _email, password: _password)) as User;
   } 
catch (err) 
   {
     showError(err.errormessage);
   }

showError(String errormessage) 
   {
 showDialog(
     context: context,
     builder: (BuildContext context)
   {
       return AlertDialog(
         title: Text('Error'),
         content: Text(errormessage),
         actions: <Widget>[
           FlatButton(
               onPressed: () {
                 Navigator.of(context).pop();
               },
               child: Text('Ok'))
         ],
       );
     });
}  ```






CodePudding user response:

You have used wrong argument in the calling of function.

Use this:

showError(err.toString());

Instead of this:

showError(err.errorMesaage);

CodePudding user response:

You have to determine what kind of error is getting caught. For example:

try {
 await auth.signInWithEmailAndPassword(email: _email, password: _password);
} on FirebaseException catch (e) {
 //the error is of type "FirebaseException". You can access its properties safely.
} catch (e) {
 // handle all other errors in this part
}

EDIT: I guess you are using firebase auth, so I have updated the example.

  • Related