Example 1 — Throw a TypeError
Pick a subclass that describes the problem.
JavaScript
try {
throw new TypeError("need number");
} catch (err) {
console.log(err.name);
} How It Works
- TypeError.name is "TypeError".
- See Error Types for more subclasses.
