Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Section 3.7 mistake? #54

Open
adecora opened this issue Jul 16, 2024 · 0 comments
Open

Section 3.7 mistake? #54

adecora opened this issue Jul 16, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@adecora
Copy link

adecora commented Jul 16, 2024

Hi, on the section about how to handle errors with asynchronous code on the solutions presented is to be consistent and always return something.

async function returnImmediately () {
  try {
    return Promise.reject(new Error('deliberate'))
  } catch (err) {
    return new Error('caught exception')
  }
}

const result = returnImmediately()
result.catch(err => console.log(`caller caught ${err}`))

The catch block is just returning the error, but in this way the returning error from the catch will be only handle by the .then.
It would be not better to return a Promise(new Error('caught exception')) as in the then block or just throwing the error return new Error('caught exception') so in this manner it will be handle by the result .catch?

@gvwilson gvwilson self-assigned this Jul 16, 2024
@gvwilson gvwilson added the bug Something isn't working label Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants