DOM methods report failures by throwing a DOMException, identified by its name. Each trigger below was tested in Chrome 1 .
| name | code | Example trigger |
|---|---|---|
| IndexSizeError | 1 | buffered.end(0) with no data |
| HierarchyRequestError | 3 | Appending <html> to <body> |
| InvalidCharacterError | 5 | createElement('1st') |
| SyntaxError | 12 | querySelector('##') |
| AbortError | 20 | signal.throwIfAborted() |
| DataCloneError | 25 | structuredClone(() => {}) |
The numeric code is legacy (newer names such as NotAllowedError have 0), so branch on name. You can create your own, for example as an abort reason:
const controller = new AbortController();
controller.abort(new DOMException('Upload cancelled by user', 'AbortError'));
try {
controller.signal.throwIfAborted();
} catch (err) {
if (!(err instanceof DOMException)) throw err; // rethrow non-DOM errors
console.log(err.name, err.code, err.message);
}Output
AbortError 20 Upload cancelled by user
Chrome now throws storage quota failures as a QuotaExceededError subclass (code 22) with quota and requested properties.