noCatchAssign
诊断类别:lint/suspicious/noCatchAssign
¥Diagnostic Category: lint/suspicious/noCatchAssign
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
no-ex-assign
¥Same as:
no-ex-assign
禁止在 catch 子句中重新分配异常。
¥Disallow reassigning exceptions in catch clauses.
分配给 catch
参数可能会产生误导和混淆。这通常是无意的,并且表明程序员犯了错误。
¥Assignment to a catch
parameter can be misleading and confusing.
It is often unintended and indicative of a programmer error.
¥Examples
¥Invalid
code-block.js:5:3 lint/suspicious/noCatchAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Reassigning a catch parameter is confusing.
3 │ } catch (e) {
4 │ e;
> 5 │ e = 10;
│ ^
6 │ }
7 │
ℹ The catch parameter is declared here:
1 │ try {
2 │
> 3 │ } catch (e) {
│ ^
4 │ e;
5 │ e = 10;
ℹ Use a local variable instead.
¥Valid
¥Related links