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

uncaughtException only catches the first uncaughtException. #5147

Closed
NoahRoseLedesma opened this issue Feb 9, 2016 · 6 comments
Closed

uncaughtException only catches the first uncaughtException. #5147

NoahRoseLedesma opened this issue Feb 9, 2016 · 6 comments
Labels
process Issues and PRs related to the process subsystem.

Comments

@NoahRoseLedesma
Copy link
Contributor

Example:

process.on('uncaughtException', (err) => {
  console.log(`Caught exception: ${err}`);
  causeError();
});

function causeError(){
console.log(notDefined);
}
causeError();

Output:

Caught exception: ReferenceError: notDefined is not defined
C:\fail.js:7
console.log(notDefined);
            ^

ReferenceError: notDefined is not defined
    at causeError (C:\fail.js:7:13)
    at process.<anonymous> (C:\fail.js:3:3)
    at emitOne (events.js:77:13)
    at process.emit (events.js:169:7)
    at process._fatalException (node.js:223:26)
[Finished in 0.256s]

Tested on 64 bit Windows, and Ubuntu. Versions 4.2.3 and 0.10.41

@mscdex mscdex added process Issues and PRs related to the process subsystem. confirmed-bug Issues with confirmed bugs. labels Feb 9, 2016
@mscdex
Copy link
Contributor

mscdex commented Feb 9, 2016

This happens with v5 and master as well. Delaying the second causeError() until the next tick does work as expected though.

Perhaps this is intentional though, since otherwise it'd lead to an infinite loop?

@mscdex mscdex removed the confirmed-bug Issues with confirmed bugs. label Feb 9, 2016
@bnoordhuis
Copy link
Member

Exactly. Working as intended, as far as I'm concerned.

@misterdjules
Copy link

@NoahRoseLedesma
Copy link
Contributor Author

That isn't a problem, waiting until the next tick as @mscdex suggested works as intended.
It would be helpful to have this safeguard noted in the documentation for this event.

@misterdjules
Copy link

@NoahRoseLedesma

That isn't a problem, waiting until the next tick as @mscdex suggested works as intended.

Please note however that the documentation mentions:

'uncaughtException' should be used to perform synchronous cleanup before shutting down the process.

So waiting until next tick is outside of this recommendation.

It would be helpful to have this safeguard noted in the documentation for this event.

Absolutely, would you be interested in submitting a pull request for that?

@evanlucas
Copy link
Contributor

Closing as the documentation PR has landed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
process Issues and PRs related to the process subsystem.
Projects
None yet
Development

No branches or pull requests

5 participants