How can I detect an uncaught serverside exception with Meteor?

I would like to catch uncaught serverside exceptions and log them, before rethrowing, but I cannot figure out how to do this in Meteor. I tried catching the uncaughtException event in Node, but Meteor seems to override this, so my handler is never called.

So, what is the way to catch uncaught exceptions in Meteor, so they may be logged, and rethrow them?

1 Like

I am in the same boat, were you able to figure out how to do this?

I can’t recall having solved this, sorry. But I haven’t used Meteor in a while.

try { … } catch(e) { throw new Meteor.Error(e); }

You can use the below code in a server section to log the error before meteor exit but you cannot prevent meteor from crash:

process.on('uncaughtException', function(err) {
    // handle the error safely

I think you have to use Meteor.bindEnvironment to make that work

No, I have create a folder called server inside my app and create a file called exception.js and put the code inside it, and it works with me, But Did you mean that to use Meteor.bindEnvironment to prevent meteor from crash?