Why am I getting the following error with this simple code below when testing on a node server?
code/app2/i.js:35
throw new Error("here")
^
Error: here
I'm actually expecting to see a stack trace as per the book 'Smashing node.js' (picture of the relevant page 35):
* node uncaught-http-js
/uncaught-http.js:4
throw new Error("here");
^
Error: This will be uncaught
at Server.<anonymous> (/uncaught-http.js:4:9)
at Server.emit(events.js:70:17)
at HttpParser.onIncoming(http.js:1514:12)
at HttpParser.onHeadersComplete(http.js:102:31)
at Socket.andata (http.js:1410:22)
at TCP.onread(net.js:354:27)
but that's not happening.
Here's the code.
function c () {
b();
};
function b () {
a();
};
function a () {
setTimeout(function () {
throw new Error('here');
}, 10);
};
c();
You don't see the whole stack trace because you throw an error in A() asynchronously (using setTimeout). If you throw it synchronously - you'll see the trace c()->b()->a().
Try it: http://jsbin.com/yirorimewe/1/edit?js,console
This is what your code does: It calls method 'c', which calls method 'b', which calls method 'a', which throws an error (inside method 'a' there is a throw error statement).
What you've posted is the stack trace (it shows you the line in the file where the error occurred).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With