void createUser(String email, String password) async {
try {
await _auth
.createUserWithEmailAndPassword(email: email, password: password)
.then((value) => Get.offAll(Home()));
} catch (e) {
Get.snackbar("Error while creating account", e.message, //Error on e.message
snackPosition: SnackPosition.BOTTOM);
}
}
Error: The getter 'message' isn't defined for the class 'Object'. Try correcting the name to the name of an existing getter, or defining a getter or field named 'message'.
知道为什么它不起作用吗?
最佳答案
原因是您捕获的 e
对象没有 message
属性。您可以使用 print(e.runtimeType)
查看它是哪种类型。如果你想捕获某种特定类型的异常,你应该尝试:
try {
//
} on SomeClass catch (e) {
print(e.message)
} catch (e) {
//
}
关于Flutter error catch e.message 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68594942/