What does it mean in node.js if process.on('uncaughException') handler is called with `undefined`?

I had a node.js (v0.8.15, latest stable) program crash, with the only output being:

timers.js:103
        if (!process.listeners('uncaughtException').length) throw e;
                                                                  ^
undefined

Thinking I'd use the uncaughtException listener to dig deeper, I registered a trivial callback:

process.on('uncaughtException', function() {
  console.log(arguments)
})

However, the only output I get now when the process crashes is:

{ '0': undefined }

There's no Exception object, no stack trace, no message — just good ol' undefined.

  • Why could this happen? What would an undefined mean in this context?
  • Any suggestions on how to better debug this? Of course I could start littering my code with random debug statements, but since I don't have a single clue as to where the error originates, that seems like asking for a wild goose chase.

I figured it out: part of my code was calling throw e in a context where it might not have been defined, and if you throw an undefined it can't have stack information attached to it or anything.

If anyone else runs into this (or something similar), check your code to see if you might be throwing something that's not an exception. (See the excellent Custom Exceptions in JavaScript question elsewhere on StackOverflow for how you should be throwing one.)