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

Wrong code in error handling chapter "Error handling, try catch" #3606

Open
tausiq2003 opened this issue Oct 31, 2023 · 2 comments
Open

Wrong code in error handling chapter "Error handling, try catch" #3606

tausiq2003 opened this issue Oct 31, 2023 · 2 comments

Comments

@tausiq2003
Copy link

There is a wrong code in the Error Handling chapter. Refer to the image and code below:

try {
  user = { /*...*/ };
} catch (err) {
  if (err instanceof ReferenceError) {
    alert('ReferenceError'); // "ReferenceError" for accessing an undefined variable
  }
}

This should output as follows in a browser environment.
image

and, nothing should be there in the terminal in Node js env. as nothing is being returned or logged.
But, as per the website when you ran the code, it shows this:

image

For reference it's the second code snippet under: https://javascript.info/try-catch#rethrowing

It might be using "use strict" internally, but its quite misleading.

@Alexandre887
Copy link
Member

From "The modern mode, 'use strict'" chapter:

image

@tausiq2003
Copy link
Author

tausiq2003 commented Nov 4, 2023

@Alexandre887 Ok understood, so I guess its a good practice to use the following, what do you think?
"use strict"
window.onerror()
process.on() in Node env.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants