The idea is simple: a rethrow key word to use inside catch blocks. This would cause errors that are re-thrown to be thrown as if from their original location, so as to not disrupt the error stack.
For example:
try {
// ...
} catch (e) {
if (!(e instanceof SomeSpecificError)) rethrow e // make it behave as it would have normally
// ... handle special error ...
}
The idea is that the error would behave exactly as if it was thrown from its original location before try catch would have intercepted it, as if there never were a try catch.
Currently, when we re-throw errors using throw, the stack trace that dev tools shows will not be exactly as where the error originated, but will include the new throw location (can be confusing).
@JackWorks the developer tools can however pause both in the location where it is thrown the first time (if break on caught exceptions is enabled) and in the location where it is re-thrown (if break on exceptions is enabled).
Dev tools can choose whatever behavior they like; regardless, a stack trace (which is what the OP described) is never generated from throwing - only from creating a new error object.
I suppose it is the devtools behavior that is not ideal. Maybe the spec can address that; that's what the rethrow idea was for. I do see that if I inspect the error.stack I see the original stack. But devtools shows me other stuff based on where an error is re-thrown.
Essentially what I was hoping for is a way to cause the try-catch to behave as if it was never there.
Hmmm, you're right, nvm, not sure what I saw. Was it always like that? Maybe an async stack threw me off; but that only adds to the stack when expanded, it looks like.
Didn't Edge (pre-Chromium) and old Safari initially set it on throw? I do recall a long time ago running into that with PhantomJS where I was getting undefined before throw and a string after. Doesn't reproduce on current iOS Safari, though.
May be worth checking behavior in various engines, especially outside the main ones (V8, JavaScriptCore, SpiderMonkey, and ChakraCore), to verify what everyone does.
IE up to v11 needs a throw statement to attach a stack trace (we still have a code path to handle that scenario in ospec). No idea for Edge and Safari.
I ran into the issue, I knew I was seeing something funky. I just didn't know how to reproduce it, but now I can any time by making Solid.js re-throw any error.
The call stack is async.
This is what I see when I pause on the line that re-throws the error: