我有这种方法。
asyncFunction1() async {
Firestore.instance.runTransaction((transaction){
var first = await transaction.something;
var second = await secondInside();
});
}
现在,我想调用此方法,并捕获其中发生的所有错误。我将如何传播错误,以便
try {asyncFunction1()}
catch(e){}
捕获runTransaction内部发生的所有错误?
最佳答案
您的内部函数错过了async
才能使用await
。如果添加它,则可以使用try
/ catch
asyncFunction1() {
Firestore.instance.runTransaction((transaction) async {
try {
var first = await transaction.something;
var second = await secondInside();
} catch(e) {
...
}
});
}
关于dart - 嵌套异步方法的抖动捕获错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50688415/