try catch块不JS
问题描述:
工作,我在下面的代码片段使用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.log()
并使用console.error()
,你越来越红
好消息,浏览器会显示错误,因为你正在登录的错误?如果你删除了'console.error()'或将其改为'console.log(“出错了”)'你可以看到它确实发现了这个错误。 – George