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

doc: improve documentation for util.types.isNativeError() #46840

Merged
merged 12 commits into from Mar 18, 2023
8 changes: 3 additions & 5 deletions doc/api/util.md
Expand Up @@ -2533,11 +2533,9 @@ console.log(util.types.isNativeError(new MyError())); // true
```

A value being `instanceof` a native error is not equivalent to `isNativeError()`
brodo marked this conversation as resolved.
Show resolved Hide resolved
returning `true` for that value. Therefore, we recommend using
`isNativeError(e) || e instanceof Error` to check if `e` is an error.

`isNativeError()` returns `true` for errors which come from a different
[realm][] while `instanceof Error` returns `false` for these errors:
returning `true` for that value. `isNativeError()` returns `true` for errors
which come from a different [realm][] while `instanceof Error` returns `false`
for these errors:

```js
const vm = require('node:vm');
Expand Down