Jonas Sicking (2013-07-16T23:30:49.000Z)
domenic at domenicdenicola.com (2013-07-19T15:56:10.184Z)
I think we have the following constraints for exceptions thrown by the DOM: ```js x instanceof DOMException ``` This *probably* needs to evaluate to true. ```js x.code == DOMException.HIERARCHY_REQUEST_ERR x.code == 3 ``` This definitely needs to evaluate to true for a bunch of older APIs. This used to be the only way to test what type of exception you had. For newer exception types we haven't added a code and so .code returns 0. For those APIs you use .name instead, see below. Obviously the exact constant and number varies with the exception type. ```js x.name == "HierarchyRequestError" ``` This should test true. This should be uncontroversial enough that I don't think it matters how much dependency there is, right? Obviously the exact value varies with the exception type. ```js x.message ``` This probably needs to contain a human readable error message. This should be uncontroversial enough that I don't think it matters how much dependency there is, right? ```js Object.toString(x) ``` I *don't* think it's important what this returns. I.e. I would guess that we can safely subclass DOMException as needed. I think we have the following constraints for properties that contain error information in APIs that currently use DOMError (IDBTransaction.error in the IndexedDB spec for example). ```js x instanceof DOMError ``` Probably doesn't matter what this returns. ```js x.name = "AbortError" ``` This should be uncontroversial enough that I don't think it matters how much dependency there is, right? ```js x.message ``` This probably needs to contain a human readable error message. This should be uncontroversial enough that I don't think it matters how much dependency there is, right? ```js Object.toString(x) ``` Probably doesn't matter what this returns. I doubt that in either case it matters if these properties live on the objects themselves, or on the prototype chain. So all in all, I think we have a lot of room for what to do in both cases. The only requirements is that exceptions *likely* need to test true for `instanceof DOMException`, and that they in some cases need to have a specific numeric code property. My recommendation would be to * Get rid of DOMError and use DOMException in its place * Add new subclasses for each exception type. I.e. exceptions with `.name == HierarchyRequestError` should also test true for `instanceof HierarchyRequestError` * Keep specifying that DOMException is a subclass of Error. This is already the case, but I wanted to make it clear that this shouldn't change. I personally think that the second bullet is a bit silly. But since that appears to be the convention that ES uses then we should stick with it.