Error caused by other error

# Michał Wadas (6 months ago)

Was there any proposal to introduce longer stack traces to language?

Eg.

try {
catch Error('foo');
} catch (err) {
throw Error('bar'); // stack trace from caught error is lost
}
# Jordan Harband (6 months ago)

Stacks themselves aren't yet in the language, see tc39/proposal-error-stacks.

As for "the stack trace from the caught error", it's lost because you let err go out of scope - if you want to preserve err.stack, you have to do so (with throw err, or by saving the information somewhere, like on your newly created error). Also, stacks are generated at the time the error object is instantiated, not at the place you throw.

# Steven R. Loomis (6 months ago)

Michał, did you perhaps mean something like a 'cause' in Java or verror? docs.oracle.com/javase/7/docs/api/java/lang/Throwable.html#initCause(java.lang.Throwable) or joyent/node-verror

Then you would have:

try {
catch Error('foo');
} catch (err) {
throw Error('bar', err);
}
# J Decker (6 months ago)

don't knwo where yuo're having problems... in node stackoverflow.com/questions/7697038/more-than-10-lines-in-a-node-js-stack-error which is

Error.stackTraceLimit = Infinity;

which maywork in chrome too