Get the actual Javascript Error object with [removed]

前端 未结 3 800
有刺的猬
有刺的猬 2020-12-13 08:34

Javascript has this great callback window.onerror. It\'s quite convenient to track any error. However, it calls with the error name, the file name and the line.

3条回答
  •  醉话见心
    2020-12-13 09:14

    this is now possible in some browsers. The spec was updated to include the actual error with stacktrace as the 5th parameter.

    the problem is that not every browser supports this yet, so you could do something like this:

    window.onerror = function(message, filename, lineno, colno, error)
    {
        if(error != null)
        {
            //handle the error with stacktrace in error.stack
        }
        else
        {
            //sadly only 'message', 'filename' and 'lineno' work here
        }
    };
    

提交回复
热议问题