In Chrome's JavaScript console, if I run this:
var that = new XMLHttpRequest();
that.open('GET', 'http://this_is_a_bad_url.com', false);
that.send();
I get an intentionally expected error:
NetworkError: A network error occurred.
I want to catch this, so I use:
var that = new XMLHttpRequest();
that.open('GET', 'http://this_is_a_bad_url.com', false);
try {
that.send();
} catch(exception) {
if(exception instanceof NetworkError) {
console.log('There was a network error.');
}
}
However, I get an error about NetworkError not being defined:
ReferenceError: NetworkError is not defined
How can I catch NetworkError?