我想要做的是捕獲所有錯誤,我處理自己。問題捕捉jQuery ajax例外
但是,當jQuery.ajax()發生錯誤,我可以知道是否有錯誤選項的錯誤。但它並沒有被我的window.onerror事件捕獲。
window.onerror = function(e) {
console.log("i was here! ERROR: ", e);
console.log("-----------");
return true; //dont show errors on console
}
$(function() {
$.ajax({
url: "asdasdasd/as/da/sdtest/asdasd",
error: function() {
// ok i know here is an error and it catches on my window.onerror. BUT look at your console, still have a GET error. That error I want to handle. Can be with try/catch or inside the window.onerror. I want that Exception object. Not this one that I created.
throw new Error("it catches, but still have errors on my console");
}
});
test[0].test = "it fails";
});
你可以在這裏測試過:http://jsfiddle.net/uHPXm/4/
,做你想要得到什麼(在解析響應會出錯)?不,我在這裏!錯誤:未捕獲錯誤:它捕獲,但我的控制檯上仍然有錯誤?或者是什麼? –
您是否看到:GET http://fiddle.jshell.net/_display/asdasdasd/as/da/sdtest/asdasd 404(NOT FOUND)。這就是我想要處理我的window.onerror,或在try/catch中。我需要Exception對象。堆棧有這個錯誤。我想獲得StackTrace。並使用我的錯誤函數拋出新的錯誤我不能 –