Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 377
    Does not even answer the question yet the most upvoted answer? Commented Mar 22, 2017 at 9:41
  • 2
    @user9993 User ho asked question was looking for detailed understanding as per chat at that time, so accordingly answer has been provided and useful to the user. that is the reason for accepted and most up votes. Commented Mar 16, 2019 at 10:42
  • 15
    @HemantMetalia But he's right, the answer shows not even the slightest attempt to answer OPs question as stated. If some very different answer in chat was answered that should remain in chat, here question and answer have no logical connection whatsoever. Commented Jul 8, 2019 at 12:21
  • And to answer the original question, it does not matter to Javascript. However, Error (and subclasses) are used by convention. They also by default provide a stack property, although that could manually be added to any other. So it's really mostly convention, program flow is not impacted by what you throw, just that you throw at all matters. You could throw "grandmother down the stairs"; and it would work the same, except that there won't be an attached stack trace and error handling functions, reporters, debuggers expect Error, or the properties that comes with, to be more precise. Commented Jul 8, 2019 at 12:23
  • What if the Error object is passed up to another promise with its own catch block? Would you once again throw a new Error object or just throw the returned object which is already an Error. Commented Dec 3, 2020 at 17:45