Module 7 · Lesson 4 of 428/32 in the course~18 min
Module lessons (4/4)
Errors in asynchronous code
Lesson preview5 hands-on exercises readyJavaScript Course · Module 7 — Asynchronous
try/catch around await, .catch on Promises, failures in Promise.all.
What you'll learn in this lesson
- Capture rejected Promises via
try / catcharoundawaitand via.catch(). - Avoid the critical mistake of writing
try { return asyncFn(); } catch ...withoutawait. - Choose correctly between
Promise.all(fail-fast at first error) andPromise.allSettled(collects all outcomes{ status, value | reason }). - Implement resilient logic that preserves partial results even when part of the requests fails.
Overview
In asynchronous code, errors do not interrupt the synchronous stack: they travel as a rejected state inside the Promise. Understanding where try/catch occurs and which combiner to use in parallel avoids UnhandledPromiseRejection and data loss.
Sections covered in this lesson
- 1Mental model: fail-fast (
Promise.all) vs partial tolerance (allSettled) - 2Progressive examples
- 3Guided laboratory
- 4Check for understanding
Pro Lesson · Module 7 — Asynchronous
Unlock "Errors in asynchronous code" and the full JavaScript Course curriculum
try/catch around await, .catch on Promises, failures in Promise.all.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in JavaScript Course plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.