firebase - 在 Flutter / Firebase Auth 注册中捕获错误
问题描述
我在flutter中从firebase身份验证实例中捕获错误时遇到了一些麻烦,我不知道出了什么问题,即使我发现了错误,代码仍然会抛出异常,此外,我不知道如何识别异常类型是否是格式错误的电子邮件、已在使用的电子邮件、弱密码等......并且没有适当的文档说明此类事情
我试过这个:
FirebaseAuth.instance.createUserWithEmailAndPassword(
email: _email, password: _password)
.then((currentUser) => {
//Execute
}).catchError((onError)=>{
print(onError)
});
并尝试了一个简单的 try-catch 块,但没有一个能捕捉到异常
解决方案
FirebaseAuth.instance.createUserWithEmailAndPassword(
email: _email, password: _password)
.then((currentUser) => {
//Execute
}).catchError((onError)=>{
//Handle error i.e display notification or toast
});
此代码确实有效,但编辑器(Visual Studio 代码)本身会引发异常并使应用程序崩溃,如果您从设备或模拟器本身运行应用程序,问题将得到解决
推荐阅读
- python - Pandas 通过从列表中返回匹配字符串的行来创建一个新的数据框,该列表与另一个数据框的 1 列中的单元格进行检查
- python - 使用 auto-upgrade-helper 升级时出现 git 错误
- google-maps - Xamarin.Forms.GoogleMaps 从 ViewModel 绑定 MoveToRegion
- android - Sentry-android 自签名 SSL 证书 (SSLPeerUnverifiedException)
- c++ - 您如何正确使用 /GUARD:CF MSVC 标志?
- snakemake - snakemake 使用动态停止而没有错误
- typescript - 如何在 Jest 测试中监视传递给反应组件的函数?
- postgresql - 比较分组中的行
- javascript - 我无法从 createAsyncThunk 函数中获取值
- python - 创建 pandas DataFrame 时保留整数