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*

8
  • 55
    what about the diff between "throw Error('whatever')" and "throw new Error('whatever')" - both work. Commented Mar 27, 2018 at 18:49
  • 31
    Error is functional, new Error is a constructor. both works same developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Mar 28, 2018 at 5:47
  • 3
    Okay, I got it. It's a function. Commented Jul 11, 2019 at 11:14
  • 9
    @Mörre what are you talking about?? Both of those quotes, "throw Error is functional" and "throw new Error is a constructor" is both factually accurate and makes clear sense. That is literally the only relevant difference between the two. throw just throws something, it doesn't care what, could be a string, an object, an instance of a class (new Something()). This answer got a lot of upvotes because it's the only correct answer. Commented Sep 7, 2021 at 9:57
  • 1
    Catching an exception is not an evil. You should have said that blocking exception propagation is evil. And even this is not the absolute evil. Evil is catching and blocking exception propagation in many points. Some inquirers I faced thought they had to do it in every function, and that was extreme evil, completely defeating the purpose of exceptions. But we do need blocking in many cases, at least on the top stack frame of each thread... Commented Nov 30, 2024 at 23:19