Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

错误捕获 #50

Open
MengZhaoFly opened this issue Dec 16, 2019 · 0 comments
Open

错误捕获 #50

MengZhaoFly opened this issue Dec 16, 2019 · 0 comments

Comments

@MengZhaoFly
Copy link
Owner

try catch

只能捕获同步代码

window.onerror

window.onerror = function (msg, url, row, col, error) {
        console.log("我已经捕获到错误");
        console.log(msg, url, row, col, error);
        return true;
    }
  1. onerror用来捕获意料之外的错误
  2. try--catch 意料之内的错误
  3. 返回true 异常才会向上抛出
  4. 当遇到静态资源错误,无法捕获

资源错误:window.addEventListener("error")

addEventListener("unhandledrejection")

捕获 promise reject

node

// 捕获错误
process.on('uncaughtException', err => {
    //do something
})
// promise
process.on('unhandledRejection', err => {
    //do something
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant