2 * @fileoverview Rule to restrict what can be thrown as an exception.
3 * @author Dieter Oberkofler
8 const astUtils = require("./utils/ast-utils");
10 //------------------------------------------------------------------------------
12 //------------------------------------------------------------------------------
19 description: "disallow throwing literals as exceptions",
20 category: "Best Practices",
22 url: "https://eslint.org/docs/rules/no-throw-literal"
28 object: "Expected an error object to be thrown.",
29 undef: "Do not throw undefined."
37 ThrowStatement(node) {
38 if (!astUtils.couldBeError(node.argument)) {
39 context.report({ node, messageId: "object" });
40 } else if (node.argument.type === "Identifier") {
41 if (node.argument.name === "undefined") {
42 context.report({ node, messageId: "undef" });