Skip to main content

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.

6
  • This fails in the case m = new InvalidInputError(); dontThrowMeYet(m);
    – Eric
    Commented Sep 6, 2014 at 12:50
  • @Eric I agree, but this seems like a pretty small limitation. I've never needed to instantiate an exception object ahead of time (excepting meta-programming uses like my code sample above). Is this really an issue for you? Commented Oct 6, 2014 at 19:21
  • Yes, the behaviour seems to be the same, so I will change my answer. I'm not 100% satisfied with the stack trace, which brings you to the "var error" line on Firefox and Chrome Commented Oct 29, 2014 at 17:31
  • 1
    @JonathanBenn I'm real late to the party, so maybe you've already picked this up. I frequently instantiate an exception object when I use asynchronous programming and Promises. Following @Eric's names, I often use m = new ... then Promise.reject(m). It's no necessity, but the code is easier to read.
    – BaldEagle
    Commented Nov 21, 2016 at 19:45
  • 2
    @JonathanBenn: (he he) in Oct 14, you seemed to think instantiating an exception object before throwing it would be rare. I gave an example of one time I do it. I won't say it's common, but it's handy to have when I want it. And, my code is more readable because the instantiating is all on one line and the rejecting all on another. I hope that does it!
    – BaldEagle
    Commented Dec 5, 2016 at 2:10