Quiz di JavaScript: Async Error Handling

Errors in asynchronous JavaScript don't always go where you expect. This quiz tests try/catch with await, .catch() and rethrowing, finally, why return await matters and what Node does with an unhandled rejection.

Medio 10 domande ~6 minuti Superato con il 80% Node.js 22

Scegli una modalità

Stai giocando come ospite: accedi per salvare XP e serie.

Domanda di esempio

Domanda 1 di 10

What does this print?

const out = [];
async function fail() {
  throw new Error("nope");
}
async function main() {
  let p;
  try {
    p = fail();
    out.push("try done");
  } catch (e) {
    out.push("caught");
  }
  await p.catch(e => out.push("later " + e.message));
  console.log(out.join(", "));
}
main();
Mostra la risposta

D. try done, later nope Calling fail() without await doesn't throw; it returns a rejected promise. The try block finishes normally, and the error only shows up when the promise is handled with .catch().

Cosa copre questo quiz

  • try/catch only catches what you await
  • Rethrowing and recovering in .catch()
  • finally in async code
  • return vs return await inside try
  • Unhandled rejections and errors in timer callbacks

Domande frequenti

Serve un account?

No. Chiunque può giocare. Accedi per salvare XP, serie, badge e cronologia.

Posso rifarlo?

Sì. Il tuo miglior punteggio resta salvato, e domande e risposte vengono mescolate ogni volta.