Bird
0
0

How can you handle errors from multiple Promises and catch any error from all of them?

hard📝 Application Q9 of 15
Node.js - Error Handling Patterns
How can you handle errors from multiple Promises and catch any error from all of them?
AUse Promise.all(promises).catch(error => handle(error))
BUse Promise.all(promises).then(error => handle(error))
CUse Promise.race(promises).catch(() => handle())
DUse Promise.allSettled(promises).catch(error => handle(error))
Step-by-Step Solution
Solution:
  1. Step 1: Understand Promise.all behavior

    Promise.all rejects immediately if any Promise rejects.
  2. Step 2: Use catch to handle any rejection

    Chaining catch after Promise.all catches any error from all Promises.
  3. Final Answer:

    Use Promise.all(promises).catch(error => handle(error)) -> Option A
  4. Quick Check:

    Catch after Promise.all handles any Promise rejection [OK]
Quick Trick: Catch errors after Promise.all to handle any rejection [OK]
Common Mistakes:
  • Using then to catch errors
  • Using Promise.race which resolves on first settled Promise
  • Assuming allSettled rejects on error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes