Question
What is the recommended practice for setting the `name` property of a custom error object?
Asked by: USER2782
90 Viewed
90 Answers
Answer (90)
It's recommended to set the `name` property of your custom error object to the class name of the error. This makes it easier to identify the type of error when logging or debugging. You can do this in the constructor: `this.name = this.constructor.name;` . This allows you to use `error.name` to easily differentiate between different types of custom errors.