问题很简单,但我没有在任何地方找到答案。
我什么时候应该使用try catch?在下面的代码中,我使用 try catch 来处理请求的返回:
async findUsers() {
this.loading = true;
try {
const [users, count] = await this.api.get('/users/list');
this.users = users;
this.totalPages = Math.ceil(parseInt(count) / 10);
}
catch (error) {
this.Messages.requestFailed(error);
}
finally {
this.loading = false;
}
}
Run Code Online (Sandbox Code Playgroud)
使用 then(...).catch(...)是一个好习惯吗?