Consider a function that fetches user information from an API. If the API call fails, you want to log an error message and then continue the execution of the function without throwing an exception to the outer scope. Which Promise method should you use to achieve this?

  • Promise.catch()
  • Promise.finally()
  • Promise.reject()
  • Promise.resolve()
You should use Promise.catch() to handle errors in a Promise. This method allows you to specify a callback function that will be called when the Promise is rejected, allowing you to log an error message and gracefully continue execution without propagating the error to the outer scope.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *