Skip to content

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

@tausiq2003

Description

@tausiq2003

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions