【发布时间】:2022-01-21 13:20:33
【问题描述】:
是否可以向用户返回异常消息?如果是,我该如何实现?我想让用户知道发生时返回的异常消息。另外,我不希望我的应用在异常发生时崩溃。
更具体地说,我想在用户尝试登录时将错误消息返回给用户。我使用 Firebase 作为我的身份验证提供程序。
为了更好地理解,我在下面包含了我的代码。
提前谢谢你。
Future<User?> signInWithEmailAndPassword(
String email,
String password,
) async {
try {
final credential = await _firebaseAuth.signInWithEmailAndPassword(
email: email, password: password);
return _userFromFirebase(credential.user);
throw Exception('Some Error occured. ');
} on auth.FirebaseAuthException catch (e, _) {
print(e);
} catch (e) {
print(e);
}
}
【问题讨论】:
标签: flutter dart exception error-handling firebase-authentication