我想使用WinJS在Windows Metro中發生未處理的異常時,使用FlyOut導航到我的應用程序的主頁並顯示錯誤。問題是程序仍然繼續到base.js中的terminateAppHandler。使用WinJS的Windows Metro中的Gracefull異常處理
這是我走到這一步:
WinJS.Application.onerror = function (customEventObject) {
// Get the error message and name for this exception
var errorMessage = customEventObject.detail.error.message;
var errorName = customEventObject.detail.error.name;
// Bind them in an optionsObject to pass with the navigation
var optionsObject = { errName: errorName, errMsg: errorMessage };
// Navigate home with information concerning the error
WinJS.Navigation.navigate("/pages/home/home.html", optionsObject);
// Need something to tell Windows that the error is "taken care" of
return false; // ??
}
我會在這裏結束,終止應用程序:
var terminateAppHandler = function (data) {
debugger;
MSApp.terminateApp(data);
};
任何建議或輸入更多的則是歡迎!
我可以在我的map.html中使用它,這是在iframe中打開的嗎? – sedran 2012-08-15 08:53:23
僅當您在iframe中的代碼中運行WinJS應用程序對象(稱爲WinJS.Application.start())時。 IFrame是一個單獨的腳本上下文。 window.onerror處理也需要單獨完成。 – 2012-08-15 23:11:56