0
0
Javascriptprogramming~5 mins

Promise error handling in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of .catch() in a JavaScript Promise?
.catch() is used to handle errors or rejections that happen in a Promise chain. It catches any error thrown or rejection from the Promise and lets you respond to it.
Click to reveal answer
beginner
How does try...catch work with async/await for error handling?
When using async/await, you can wrap the await call inside a try block. If the Promise rejects, the error is caught in the catch block, allowing you to handle it cleanly.
Click to reveal answer
beginner
What happens if you don't handle a rejected Promise?
If a Promise rejects and you don't handle it with .catch() or try...catch, it causes an unhandled promise rejection. This can crash your program or cause unexpected behavior.
Click to reveal answer
intermediate
Can you chain multiple .catch() handlers on a Promise?
No, only the first .catch() in the chain will catch the error. After an error is caught, the chain continues normally unless you throw another error.
Click to reveal answer
intermediate
How can you handle errors in multiple Promises running in parallel?
You can use Promise.allSettled() to wait for all Promises to finish, then check which ones failed. Or use Promise.all() with a .catch() to handle if any reject.
Click to reveal answer
Which method is used to catch errors in a Promise chain?
A.catch()
B.then()
C.finally()
D.resolve()
What happens if a Promise rejects but no .catch() is provided?
AThe error is ignored silently
BAn unhandled promise rejection occurs
CThe Promise automatically retries
DThe Promise resolves with undefined
How do you handle errors when using async/await?
AUse <code>.catch()</code> after the await
BUse <code>finally</code> block only
CErrors are handled automatically
DWrap the <code>await</code> call in a <code>try...catch</code> block
Which Promise method lets you wait for all Promises to finish regardless of success or failure?
APromise.allSettled()
BPromise.race()
CPromise.all()
DPromise.resolve()
If you want to handle errors only once in a Promise chain, where should you place .catch()?
AAt the start of the chain
BAfter every <code>.then()</code>
CAt the end of the chain
DYou don't need <code>.catch()</code>
Explain how to handle errors in a Promise chain using .catch().
Think about how you catch mistakes in a sequence of steps.
You got /4 concepts.
    Describe how try...catch works with async/await for error handling.
    Imagine waiting for a task and catching problems as if it was normal code.
    You got /4 concepts.