Open devinrhode2 opened 10 years ago
Figured out how to list all error types that are an instanceof Error
:
var thing;
var forbiddenKeys = [];
var gp = '';
var p = '';
var allKeys = Object.getOwnPropertyNames(window);
var index = allKeys.length;
var errorTypes = [];
while (index > 0) {
index--
p = allKeys[index];
if (~forbiddenKeys.indexOf(p)) return;
gp = p;
thing = window[p];
try {
var aThing = new thing('a');
if (aThing instanceof Error) {
console.log(p);
} else if (aThing.message && (aThing.stack || aThing.name)) {
console.log('not error', p);
}
} catch ( _ ) {
_;
}
}
Checking in Opera, Chorme, Firefox, and Safari these are:
Error
TypeError
SyntaxError
ReferenceError
URIError
EvalError
RangeError
But FF also has InternalError
I was also curious about all other globals that have "Error" or "Exception" in their identifier, so here's a snippit for that:
var allKeys = Object.getOwnPropertyNames(window);
var p = '';
for (var i = 0; i < allKeys.length; i++) {
p = allKeys[i];
try {
if (~p.indexOf('Error') || ~p.indexOf('Exception') ) {
console.log(p);
}
} catch (e) { e; }
}
Chrome:
ErrorEvent
MediaError
MediaKeyError
webkitSpeechRecognitionError
FileError
DOMException
AutocompleteErrorEvent
Opera:
ErrorEvent
MediaError
MediaKeyError
FileError
DOMException
AutocompleteErrorEvent
Firefox:
DOMError
MediaError
DOMException
GetUserMediaErrorCallback
DataErrorEvent
GeoPositionErrorCallback
SpeechRecognitionError
GeoPositionError
Safari:
DOMException
SQLException
ErrorEvent
WebKitMediaKeyError
MediaError
XMLHttpRequestException
RangeException
XPathException
FileError
EventException
SVGException
Only "MediaError" is common amongst these 4 browsers, along the above list of Error
types.
Most people most of the time probably don't care about the instanceof an exception. Here is some code I'm removing but is still pretty valuable: