对try...catch
开始懵了
对于从数据库增删改查数据,例如在做一个删除用户的操作,是不是都需要捕获异常。
是不是对任何数据库操作都需要做异常处理,try.catch?
[是的话我觉得好麻烦]
User.destroyUser = async function (Id) {
try {
const res = await this.destroy({
where: {
Id
}
})
} catch (e) {
throw(e)
}
return res
}
封装一个函数,比如叫
warp()
,这个wrap
的参数就是你要处理的那个逻辑。