如何在 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