Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm pretty used to seeing strings being thrown. Maybe I am just old?


There was a point years ago when I was surprised to find out that you can throw things other than strings...


subclassing Error was a mess.. almost 'not supported'.

For old times sake.. https://stackoverflow.com/questions/1382107/whats-a-good-way...


I think the last time I threw anything else than an Error was in 2012 or so.

Old it is I guess - both of us.


I either throw an Error or something that extends Error. Makes sense, right?


Same, 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!


I 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.


That 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: