Valid JS-Dev-101 Dumps shared by EduDump.com for Helping Passing JS-Dev-101 Exam! EduDump.com now offer the newest JS-Dev-101 exam dumps, the EduDump.com JS-Dev-101 exam questions have been updated and answers have been corrected get the newest EduDump.com JS-Dev-101 dumps with Test Engine here:
Original code: 01 let requestPromise = client.getRequest; 03 requestPromise().then((response) => { 04 handleResponse(response); 05 }); The developer wants to gracefully handle errors from a Promise-based GET request. Which code modification is correct?
Correct Answer: C
Key JavaScript Promise rule: try...catch does not catch asynchronous errors that occur in Promise chains. Therefore, the correct way to handle errors in a Promise is: promise.then(...).catch(...); Analysis of options: A and B: Both wrap asynchronous code in try...catch, which does not catch Promise rejections. try...catch only catches errors thrown synchronously inside the block. C: Correct. A .catch() on the Promise chain handles any error from the Promise returned by requestPromise(). D: .finally() executes regardless of success or failure, but it does not receive the error object, so it cannot handle the error. Thus the only valid solution is option C. JavaScript Knowledge Reference (text-only) Promise rejections must be handled with .catch(). try...catch only handles synchronous code. .finally() does not receive a rejection reason.