
no-ex-assign
禁止在 catch
子句中重新赋值异常
✅ 推荐
在配置文件中使用来自 @eslint/js
的 recommended
配置将启用此规则
如果 try
语句中的 catch
子句意外(或故意)将另一个值赋给异常参数,则无法从该点起引用错误。由于没有 arguments
对象提供对这些数据的替代访问,因此对参数的赋值绝对具有破坏性。
规则详情
此规则禁止在 catch
子句中重新赋值异常。
此规则的错误代码示例
在在线运行中打开
/*eslint no-ex-assign: "error"*/
try {
// code
} catch (e) {
= 10;
}
此规则的正确代码示例
在在线运行中打开
/*eslint no-ex-assign: "error"*/
try {
// code
} catch (e) {
var foo = 10;
}
版本
此规则是在 ESLint v0.0.9 中引入的。
进一步阅读
