So, quick poll on #JavaScript throw: should you always throw an instance of
Error(), or is it ok to throw anything?
I'm also happy to hear your reasoning for the choice.
A static archive of Markus Tacker's tweets. Follow me on Mastodon: @[email protected].
So, quick poll on #JavaScript throw: should you always throw an instance of
Error(), or is it ok to throw anything?
I'm also happy to hear your reasoning for the choice.
You can throw undefined, btw.
I personally think you should always throw an Error instance. Technically this
is superfluous, since everywhere you catch it, you know you have an error.
But: Errors have attached stack traces. So it's easier to debug.