如何在JavaScript中编写全局错误处理程序?
以下全局错误处理程序将显示如何捕获未处理的异常–
示例
<!DOCTYPE html><html>
<body>
<script>
window.onerror = function(errMsg, url, line, column, error) {
var result = !column ? '' : '\ncolumn: ' + column;
result += !error;
document.write("Error= " + errMsg + "\nurl= " + url + "\nline= " + line + result);
var suppressErrorAlert = true;
return suppressErrorAlert;
};
setTimeout(function() {
eval("{");
}, 500)
</script>
</body>
</html>
以上是 如何在JavaScript中编写全局错误处理程序? 的全部内容, 来源链接: utcz.com/z/351384.html