Skip to main content

throw-new-error

Require new when throwing error instances.

Targeted pattern scopeโ€‹

This rule targets thrown error-constructor call expressions.

What this rule reportsโ€‹

This rule reports throw Error(...) and related patterns without new.

Why this rule existsโ€‹

throw new Error(...) is explicit and consistent with constructor semantics.

โŒ Incorrectโ€‹

throw Error("Boom");

โœ… Correctโ€‹

throw new Error("Boom");

Behavior and migration notesโ€‹

This rule forwards options and behavior to unicorn/throw-new-error.

  • Lifecycle: Deprecated and frozen.
  • Deprecated since: v1.0.0
  • Available until: v2.0.0
  • Use instead: unicorn/throw-new-error

Additional examplesโ€‹

throw TypeError("invalid");
// โŒ reported by forwarded unicorn rule

throw new TypeError("invalid");
// โœ… valid

ESLint flat config exampleโ€‹

import etcMisc from "eslint-plugin-etc-misc";

export default [
{
plugins: { "etc-misc": etcMisc },
rules: {
"etc-misc/throw-new-error": "error",
},
},
];

When not to use itโ€‹

Disable this rule if your codebase intentionally uses the function-call style for Error constructors.

Package documentationโ€‹

Rule catalog ID: R075

Further readingโ€‹

Adoption resourcesโ€‹

  • Start at warning level in CI, then move to error after cleanup.
  • Use focused codemods/autofix batches per package or directory.