📜  关于未捕获异常的 javascript - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:59.728000             🧑  作者: Mango

代码示例1
// NODE JS
process.on('uncaughtException', function (error) {
    // Handle the error
});
        

// Browser
window.onunhandledrejection = event => {
  console.warn(`UNHANDLED PROMISE REJECTION: ${event.reason}`);
};

window.onerror = function(message, source, lineNumber, colno, error) {
  console.warn(`UNHANDLED ERROR: ${error.stack}`);
};

// OR

window.addEventListener('error', function(event) { ... })