Hacker News new | past | comments | ask | show | jobs | submit login
Create-error.js – A simple helper for subclassed errors in Javascript (github.com/tgriesser)
13 points by tgriesser on Dec 6, 2013 | hide | past | favorite | 2 comments



I don't understand why this is more useful than just creating an object and settings its prototype to `Error`.

Anyone care to explain?


Well, in that case you'd lose the stack trace. If you just set the object's prototype to Error.prototype, and you add additional properties to the object's prototype you'd be modifying the Error's prototype as well.

The aim of this helper is to create a custom object which has the same functionality as a traditional Error object.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: