I a while ago i used to use Verror from joyent to not lose the stacktrace when rethrowing, I have just done a test with node v12 without Verror and stack trace seems to be persisted without the use of error.
I then was looking at the use of Error.captureStackTrace, it states to use this in your errors so that the Error is not added to the stack.
I don't what i am doing wrong but with or without Error.captureStackTrace - the stack trace is the same..
I would like to know the current status of the use of the captureStackTrace as i see no difference :-) and also the use of VError that doesn't seem to be needed anymore.
In the documentation it states that the .stack isn't available without calling the captureStackTrace but I see it available each time, with or without the captureStackTrace
here is an example of 2 x errors
class MyErrorOne extends Error {
constructor(message) {
super(message);
Error.captureStackTrace(this, this.constructor);
}
}
class MyErrorTwo extends Error {
constructor(message) {
super(message);
Error.captureStackTrace(this, this.constructor);
}
}
I tried them by commenting out the captureStackTrace in EACH error and the stacktrace is the same.
Can anyone help ?
Here is my code to test calling the errors
const DoOne = () => {
try {
console.log("executing do one");
DoTwo();
} catch (error) {
console.log("error in DoOne", error);
console.log("here is the stack ", error.stack);
throw new MyErrorOne("threw error from doone in myerrorone");
// throw error;
}
};
const DoTwo = () => {
try {
console.log("executing do two");
throw new MyErrorTwo("threw error from dotwo in myerrortwo");
} catch (error) {
console.log("error in DoTwo", error);
throw error;
}
};
DoOne();