-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I've made "throw expression" package #15
Comments
Doesn't that change the stack trace? |
It depends on the implementation I suppose (of both the library and the runtime), since In v8, you get the correct stack trace in function f() {
g();
}
function g() {
thrw(new Error());
}
function thrw(e) { throw e; }
try {
f();
}
catch (e) {
console.log(e.stack);
// Error
// at g (C:\scratch\thrw.js:6:10)
// at f (C:\scratch\thrw.js:2:5)
// at Object.<anonymous> (C:\scratch\thrw.js:12:5)
// at Module._compile (node:internal/modules/cjs/loader:1101:14)
// at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
// at Module.load (node:internal/modules/cjs/loader:981:32)
// at Function.Module._load (node:internal/modules/cjs/loader:822:12)
// at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
// at node:internal/main/run_main_module:17:47
} In Chakra, |
ah, yes, good point - if you make the error object inline in the thrw call then it'd be fine. |
I prefer the toss terminology myself 😉 |
Love seeing that I'm not the only one with the same idea! |
Usually I just use something like:
Or
Or, my preference:
It's about the same amount of code as |
@JC3 |
Since this proposal is still not implemented, and even using transpilers would break a lot of other tools working with the code, I've made a tiny package, thrw, and have been using it in a lot of projects, both personal and professional.
I want to share this package with other people. Would it be a good idea to add a link to it somwhere in this repository?
The text was updated successfully, but these errors were encountered: