JS Errors Intro
Errors tell you that an operation could not finish normally. Catch an expected failure where you can explain or recover from it.
Where to run this
This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.
A practical example
try {
JSON.parse("not JSON");
} catch (error) {
console.log(error.name);
}
What happens
Parsing invalid JSON throws SyntaxError, which the catch block reports.