While it is okay possible to throw any value, it is generally considered poor form to throw anything other than an instance of Error or one of its subclasses. There are several reasons for this:
- Catching code may expect the thrown object to have the usual
message,stacktrace, andnameproperties that appear onErrors. - Lack of a stacktrace makes debugging problematic, especially in the case of uncaught exceptions / unhandled rejections. E.g. Debugging an “Uncaught [Object object]” error can be particularly painful.