Useful error messages with ExceptionMessages
When throwing a DOM exception, please ensure that you take the time to write an error message that helps developers understand what's gone wrong, and what they can do to fix things. Something like exceptionState.throwDOMException(InvalidStateError, "This object's 'readyState' is not 'open'.") can make the difference between a 5 minute fix, and an all-day facepalming session. The ExceptionMessages helper class has a variety of methods that help you construct a more detailed and specific message in a consistent way. Perhaps:
es.throwDOMException(TypeMismatchError, ExceptionMessages::argumentNullOrIncorrectType(1, "Node"));
That will give the user an exception object whose message property reads "Failed to execute "method" on "Interface": The 1st argument is null, or an invalid Node object.", which has been scientifically measured to be 83 times more useful than an exception lacking that detail. In general, developers will be much happier if we give them enough data to resolve an issue right away, so please don't be afraid of adding detail.
Just add #include "bindings/v8/ExceptionMessages.h" and go wild.
- Always throw SecurityError exceptions via ExceptionState::throwSecurityError.
- Add additional detail via an unsanitizedMessage (second parameter) if relevant.