Asynchronous try/catch

With async/await, errors are handled with try/catch: an await on a rejected promise throws an exception, caught by catch. Without try/catch, the async function's promise is rejected. finally runs cleanup in every case.

Example

try {
  const data = await charger()
} catch (e) {
  console.error(e)
}

Related concepts

The whole glossary