繁体   English   中英

未处理的异常处理程序缺少异常信息

[英]unhandled exception handler missing exception info

与在这个问题中提出的问题类似,我试图将所有未处理的错误推送到我们的遥测管道,以便为工程师提供足够的信息来调试问题。

未处理的异常处理程序以下列方式设置:

window.onerror = (event: Event | string, source?: string, lineno?: number, colno?: number, error?: Error) => {
        const message: string = `src: ${source} line: ${lineno} col: ${colno}`;
        logError(error || new Error(event.toString()), message);
    };

这似乎与文档一致。

在遥测开始流动后,我观察到以下内容:

  1. 对于大多数处理程序调用, error变量是 null。
  2. linenocolno也是null0

我知道CROSSORIGIN设置,它似乎设置正确。

我找不到任何严格的规则来描述在未处理的回调期间提供的信息。 我也在寻找有关我们设置未处理回调的方式的反馈以及潜在改进的想法。

<script type="text/javascript">
window.onerror = function(msg, url, line, col, error) {

    const message: string = `src: ${source} line: ${lineno} col: ${colno}`;
    logError(error || new Error(event.toString()), message);

   // Send your telemetry info here

   // Many browsers show alerts dialogs when errors are founded, so return true to suppress it.
   return true;
};
</script>

window.onerror 何时触发?

该事件在以下任一情况下引发

  1. 有一个未捕获的异常
  2. 发生编译时错误

例如:

未捕获的异常

  • 抛出“一些消息”
  • 调用或引用未定义;
  • cross_origin_iframe.contentWindow.document;,安全异常

编译错误

<script>{</script>
<script>for(;)</script>
<script>"oops</script>
setTimeout("{", 10);, it will attempt to compile the first argument as a script

支持 window.onerror 的浏览器

  • 铬 13+
  • Firefox 6.0+
  • 互联网浏览器 5.5+
  • 歌剧 11.60+
  • Safari 5.1+

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM