no-ex-assign
禁止在 catch 条款中重新分配例外情况
在 配置文件 中使用来自 @eslint/js 的 recommended 配置可以启用此规则
如果 try 语句中的 catch 子句不小心(或故意)给异常参数赋了另一个值,那么从那时起就无法再引用该错误。
由于没有 arguments 对象可以提供对这些数据的替代访问,因此对参数的赋值是完全破坏性的。
🌐 If a catch clause in a try statement accidentally (or purposely) assigns another value to the exception parameter, it is impossible to refer to the error from that point on.
Since there is no arguments object to offer alternative access to this data, assignment of the parameter is absolutely destructive.
规则详情
🌐 Rule Details
此规则不允许在 catch 子句中重新分配异常。
🌐 This rule disallows reassigning exceptions in catch clauses.
此规则的错误代码示例:
🌐 Examples of incorrect code for this rule:
/*eslint no-ex-assign: "error"*/
try {
// code
} catch (e) {
e = 10;
}
符合此规则的正确代码示例:
🌐 Examples of correct code for this rule:
/*eslint no-ex-assign: "error"*/
try {
// code
} catch (e) {
const foo = 10;
}
选项
🌐 Options
此规则没有选项。
🌐 This rule has no options.
版本
此规则是在 ESLint v0.0.9 中引入。