XMLHttpRequest in a try catch safari (local)

try {<br> this.xmlHttpRequest = new XMLHttpRequest();<br> this.xmlHttpRequest.onreadystatechange = this.onReadyStateChangeHandler_;<br> this.xmlHttpRequest.open('GET', this.url of this.async_);<br> this.xmlHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');<br> this.xmlHttpRequest.send(null);<br> } catch(error) {<br> Alert('error')<br> }<br>

When you open a channel to file this.xmlHttpRequest.open('GET', this.url of this.async_); if:
1. The request is asynchronous;
2. Loading takes place in the locale;
3. The file at the specified url is absent;
4. Safari || Chrome (last version).

The try catch block doesn't work XMLHttpRequest calls onreadystatechange with readyState == 4 and status == 0, statusText==", responseText==".
Tell me how to overcome and catch the error not a valid url for the asynchronous request.
October 10th 19 at 15:34
2 answers
October 10th 19 at 15:36
Too faced, in Chrome, when writing extensions. In the end, caught status == 0 && responseText == "". Very interesting.
October 10th 19 at 15:38
www.w3.org/TR/XMLHttpRequest/#the-send-method

The idea is that what you are describing is a network error. A network error should be handled like this:
When something is said to be a network error run the request error steps for exception NETWORK_ERR.

Looking that will run when request error:
When something is said to be a request error for exception exception run these steps:
<...>
If the asynchronous flag is false raise an exception exception and terminate the overall set of steps.

Ie, Chrome, Safari, Firefox work correctly without giving an error if the request asincroni. IE and Opera no.
To catch the error, it is necessary to handle the readystatechange event, Yes.
Correct me if I'm wrong.

Find more questions by tags JavaScript