In all the documentation I've read, it consistently advises to both throw and initialize errors on the same line. For example:
throw new Error("My error");
But what if you were to first initialize the error and then throw it on separate lines?
For instance, when creating a new error instance like so:
const myErrorInstance = new Error("Defined error"); // Initialization
And later throwing that instance within a function:
throw myErrorInstance; // Throwing it
I wonder, does the stack get attached when the error instance is initialized or when it's actually thrown?