Introduction
DOMError is an interface defined by the DOM.
I would like to check whether a browser supports it. A naive check is
window.DOMError !== undefined
A better check would be to use an action that throws a DOMError and check that
err instanceof DOMError === true
Question
What actions throw DOMErrors?
A
DOMError
is a non-exception-based error condition. It will never be thrown, except in as much as an object that implements bothDOMError
andDOMException
might be thrown as aDOMException
.It is expected that the concrete class implementing
DOMError
andDOMException
may be the same in many DOM implementations, but they are separated in the spec for the benefit of languages with bindings toDOMException
that would make it hard to re-use the existing implementation. For example languages without native exceptions may have an out-of-band error-signalling channel that can't really be dumped as an object onto a property like aDOMError
can.DOMError as drafted in DOM4 is a trivial placeholder, holding only a name string. It is expected that any specs that build on it will add some properties to encapsulate more useful information.
Currently it is used by the W3 File API for errors in
FileReader
, which, being an asynchronous interface, doesn't have anywhere useful to throw exceptions. The File API doesn't add any extra properties toDOMError
or a subinterface as yet, but both it and the DOM4 spec are likely to undergo changes before they get near Recommendation status.DOMError as originally introduced in DOM Level 3 Core provided an extended error interface with more in-depth information on where in the document the error occurred. It was intended for the serialiser and parser processes in DOM Level 3 LS, but is included in Core for the use of the
document.normalizeDocument
method, which also simulates a serialise/parse cycle.Today's browsers don't have a DOMError because they don't support any of DOM 4, DOM Level 3 LS , or
normalizeDocument
. But other non-browser DOM implementations may; pxdom for one has the DOM 3 interfaces.