4 ms·
I'm pretty used to seeing strings being thrown. Maybe I am just old?
by andrelaszlo 5y ago
I'm pretty used to seeing strings being thrown. Maybe I am just old?
- Gravyness 5y agoSame, although I always thought it was a terrible practice as I'm always reading error.message or error.stack straight away. And if an error does not have a stack then I will call the police on whoever wrote this shit!
- prmph 5y agoI recently started throwing bare string instead of Error objects, just because of all the Error: prefixes that are prepended to the error message when you throw an Error. It just clutters up the stack trace. More generally I wish there was an Error constructor that automatically records and the function, arguments, and other semantically meaningful information when called. File and line numbers do not make for a pleasant experience when inspecting a stack trace.
- nimbix 5y agoThere was a point years ago when I was surprised to find out that you can throw things other than strings...
- jibbit 5y agosubclassing Error was a mess.. almost 'not supported'. For old times sake.. https://stackoverflow.com/questions/1382107/whats-a-good-way-to-extend-error-in-javascript https://stackoverflow.com/questions/1382107/whats-a-good-way...
- junon 5y agoThat was the norm maybe 15-20 years ago. These days it's a mortal sin to throw from something that isn't derived from Error.
- Tade0 5y agoI think the last time I threw anything else than an Error was in 2012 or so. Old it is I guess - both of us.
- AA-BA-94-2A-56 5y agoI either throw an Error or something that extends Error. Makes sense, right?