Skip to main content

JavaScript Promise Errors — exercises and bug fixes

5 hands-on exercises and 5 find-the-bug challenges for the JavaScript Promise Errors lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.

Exercises(5)

  1. 1

    Catch a rejection

    easy10 min

    Catch a rejected promise and report the message.

  2. 2

    Catch a thrown error

    easy10 min

    Throw inside a then and catch it.

  3. 3

    Clean up with finally

    easy10 min

    Handle a rejection then report that cleanup ran.

  4. 4

    Check the error type

    easy10 min

    Report whether the rejection reason is an Error object.

  5. 5

    Recover from a failure

    medium10 min

    Catch a rejection and continue the chain with a fallback value.

Find the bug(5)

  1. 1

    Fix the missing catch

    easy8 min

    The rejection is never handled, so nothing is reported.

  2. 2

    Fix the message read from a string

    easy8 min

    A rejection reason that is a plain string has no message property.

  3. 3

    Fix finally expected to receive a value

    easy8 min

    finally gets no argument; the value passes straight through.

  4. 4

    Fix the throw outside the chain

    easy8 min

    A throw outside a promise handler is not caught by catch.

  5. 5

    Fix the chain that stops at the catch

    easy8 min

    The catch should return a value so the next step can use it.

Ready to write the code?

The editor, the automatic checks and the worked solutions open up with an account.

Open the workspace