Mozilla says that we can define an object and throw it.
This way, we can encapsulate more than a simple string message and send it to the exception consumer (the catch
block, or the then
method of promises).
However, I don't want to constantly define types in my JS code.
Is it possible to throw anonymous objects?
I tried throw new Error({ firstKey: firstValue, secondKey: secondValue })
and it does not work. I get [object Object]
.