Skip to content

oxc/missing-throw Correctness

This rule is turned on by default.
💡 A suggestion is available for this rule.

What it does

Checks whether the throw keyword is missing in front of a new expression.

Why is this bad?

The throw keyword is required in front of a new expression to throw an error. Omitting it is usually a mistake.

Example

Examples of incorrect code for this rule:

javascript
function foo() {
  throw Error();
}
const foo = () => {
  new Error();
};

Examples of correct code for this rule:

javascript
function foo() {
  throw new Error();
}
const foo = () => {
  throw new Error();
};

References

Released under the MIT License.