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