-2
工作,我在下面的代碼片段使用Kendo Notfication Widget
:try catch塊不JS
function notifySuccess(message) {
var notificationWidget = $('#notification').data('kendoNotification');
try {
var notifications = notificationWidget.getNotifications();
if (notifications !== 'undefined') {
notifications.parent().remove();
}
notificationWidget.success(message);
} catch (e) {
console.error("Exception thrown", e.stack);
}
}
突然,有時在瀏覽器中發生異常,這就是爲什麼我周圍有一個try catch
塊中的語句在療法首位:
Uncaught TypeError: Cannot read property 'getNotifications' of undefined
at notifySuccess (myCode:595)
at HTMLBodyElement.success (<anonymous>:137:32)
at i (jquery-3.1.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-3.1.1.min.js:2)
at A (jquery-3.1.1.min.js:4)
at XMLHttpRequest.<anonymous> (jquery-3.1.1.min.js:4)
瀏覽器有時仍然顯示此錯誤。
顯然我的catch
塊沒有發現這個錯誤。 任何想法?
thx
好消息,瀏覽器會顯示錯誤,因爲你正在登錄的錯誤?如果你刪除了'console.error()'或將其改爲'console.log(「出錯了」)'你可以看到它確實發現了這個錯誤。 – George