The output of this code when run in node.js is the stack trace of an error that occurs on the last line (line number 9). The error that occurs on line 7 is somehow 'absorbed' by node. Even if I wrap it in a try/catch statement I can't seem to get as detailed a stack trace output as I do from node's default error handling code.
How can I catch the error on line 7 and get as much detail about it as I can from line 9?
jsdom = require('jsdom');
var testHTML = "<html><head><title>Hi!</title></head><body><p>Hi!</p></body></html>";
jsdom.jQueryify(
jsdom.jsdom(testHTML).createWindow(),
'http://code.jquery.com/jquery-1.4.2.min.js' ,
function() {
var a = broken();
});
var a = broken();
(NB: This is a simplified example from a much more complex script I'm writing with errors that occur in a 'deeply' nested stack that forms as a result of a call from within a jQueryify call-back, and debugging it is an absolute pain right now without being able to get detailed stats on the error)
It's asynchronous, so you can't put a try/catch
around the call to jQueryify
. You must put a try catch at the top level callback in your callback
jsdom = require('jsdom');
var testHTML = "<html><head><title>Hi!</title></head><body><p>Hi!</p></body></html>";
jsdom.jQueryify(
jsdom.jsdom(testHTML).createWindow(),
'http://code.jquery.com/jquery-1.4.2.min.js' ,
function() {
try {
var a = broken();
} catch(e) {
// Handle the error here
}
});
var a = broken();