如何在 JavaScript 中编写全局错误处理程序?
以下全局错误处理程序将展示如何捕获未处理的异常 -
示例
<!DOCTYPE html>
<html>
<body>
<script>
window.onerror = function(errMsg, url, line, column, error) {
var result = !column ? '' : '
column: ' + column;
result += !error;
document.write("Error= " + errMsg + "
url= " + url + "
line= " + line + result);
var suppressErrorAlert = true;
return suppressErrorAlert;
};
setTimeout(function() {
eval("{");
}, 500)
</script>
</body>
</html>
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP