Which keyword is used to throw a custom error?
Answer
throw
Answer
throw
The `throw` keyword is used to throw a custom error in JavaScript.
A program can use `throw` with an `Error` object, commonly written as `throw new Error("Something went wrong")`. This immediately stops normal execution at that point and searches for a matching surrounding `catch` block. The error message can describe the particular condition that the program detected.
`try` defines code in which an exception may occur, and `catch` handles an exception after it has been thrown; neither keyword throws the error itself. The identifier `error` is often used as the parameter name in a catch clause, but it is not a special throwing keyword.
JavaScript technically permits throwing many values, including strings, numbers, or ordinary objects. Throwing an `Error` instance is generally preferred because it carries a message, a name, and usually a stack trace, making debugging easier. Built-in subclasses such as `TypeError`, `RangeError`, and `SyntaxError` provide more specific categories when appropriate.
Source: Wikipedia · fact-checked Aug. 2026