0

With try/catch it's generally considered incorrect to throw a string or other random object. You're supposed to construct a new Error and throw that instead.

Does this also apply to rejected promises?

callum
  • 34,206
  • 35
  • 106
  • 163
  • 1
    It's not strict. If you think an `Error` object is not a fit for you, you can reject with a custom object, or whatever data structure makes sense to you. `data structures > code`. – Gaston Sanchez Mar 04 '16 at 15:44

1 Answers1

2

The spec says, regarding the argument to reject:

Typically it will be an Error object.

So it's expected that it will be an Error, but it's not essential. Use whatever is semantically correct in your situation.

James Thorpe
  • 31,411
  • 5
  • 72
  • 93