Lesson 7 of 8

Promise errors

Goal

What you don't await, you can't catch

01

Explanation

A try/catch block only catches what is thrown inside it. A promise you don't await rejects later, after execution has already left the block, so catch never sees it, and you end up with a page that says "Saved." even though saving failed.

The fix is one word: await inside try. The rejection then becomes an ordinary error thrown from that same line, and it reaches catch.

Sometimes you deliberately don't wait, like when you send an analytics event that isn't worth delaying the user for. But a rejection nobody handles doesn't disappear: it shows up in the console as an "unhandled rejection" and its cause gets lost. That's why every promise you don't await needs its own .catch.

02

Your task

Fix save() so that #msg shows the real reason for a failure and success is never announced before it happens, then handle the rejection from track without awaiting it.

Checks

4 checks
  1. A failed save doesn't look like a success
  2. The failure message gives the real reason
  3. Success isn't announced before it happens
  4. No rejection goes unhandled
03

Hints

0/3
Track lessons0 of 8 done

Learn how to read an error message, check inputs before you use them, and catch the errors worth handling.

Intermediate level, 8 lessons, 1.5 hours in total.

index.html
Preview
index.html100%
–/4

Press “Run and check” to grade your code.

4 checks listed under “Your task”.

Track lessons0 of 8 done

Learn how to read an error message, check inputs before you use them, and catch the errors worth handling.

Intermediate level, 8 lessons, 1.5 hours in total.