Error handling

Error handling in JavaScript relies on try, catch, and finally: risky code runs in try, the thrown error is caught in catch, and finally runs in all cases. You throw your own errors with throw new Error('message').

Example

try {
  JSON.parse(texte)
} catch (e) {
  console.error(e.message)
}

Related concepts

The whole glossary