Firebase,我如何捕获异常并告诉用户它? [复制]
Posted
技术标签:
【中文标题】Firebase,我如何捕获异常并告诉用户它? [复制]【英文标题】:Firebase, how do I catch a exception and tell the user about it? [duplicate] 【发布时间】:2021-10-23 19:23:04 【问题描述】:Future<Users?>createUserWithEmailAndPassword(String email, String password) async
final credential = await _firebaseAuth.createUserWithEmailAndPassword(
email: email,
password: password
);
return _userFromFirebase(credential.user);
【问题讨论】:
【参考方案1】:您可以使用 try/catch
捕获异常,并以多种方式将其显示在 UI 上。示例
Future<Users?> createUserWithEmailAndPassword(
String email,
String password,
) async
try
final credential = await _firebaseAuth.createUserWithEmailAndPassword(
email: email,
password: password,
);
return _userFromFirebase(credential.user);
on FirebaseException catch (e)
// FirebaseException
print(e.message);
catch (e)
// all other exceptions
print(e);
【讨论】:
swedischeef thnks 在 loginPage onPressed 按钮上工作 onPressed: () async if(_formKey.currentState!.validate()) try await authService.signInWithEmailPassword( emailController.text, passwordController.text ); Navigator.pop(上下文); catch(e) await showDialog(context: context, builder: (BuildContext) => AlertDialog( title: Text('ERROR'), content: Text(e.toString()), actions:以上是关于Firebase,我如何捕获异常并告诉用户它? [复制]的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Firebase (Crashlytics) 记录非致命(捕获)异常
Firebase 数据库 - Firebase 数据库运行循环 (19.3.0) 中未捕获的异常
由于未捕获的异常“com.firebase.durabledeeplink”而终止应用程序,原因:“配置持久深度链接失败