the cast does not spill out through a callback like this. Pass the error handling callback and handle it manually.
Let me illustrate your stack traces.
There is no stacktrace connection between the onreadystatechange function and the connectTo function. Therefore, when you make a mistake, it never bubbles up to the catch try block around connectTo.
What firefox does says "Oh you did something that doesn't work. let me fix that for you and do what you think it does"
function connectTo(url, err) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, false);
xhr.onreadystatechange = function () {
if (xhr.readyState == xhr.DONE) {
err.call(this, new Error("troubles"));
}
};
xhr.send();
}
connectTo("http://www.google.com", function(e) {
console.log(e);
});
source
share