在bootstrapped firefox扩展中设置全局错误处理程序

时间:2013-12-27 09:39:28

标签: javascript firefox exception error-handling firefox-addon

我正在为Firefox构建一个引导扩展(因为我需要tcp套接字而不使用附加SDK)。尽管我的所有IO调用等都受到try / catch的保护,但我希望有一个全局错误处理程序以防万一。 Bootstrapped扩展无法访问窗口对象,因此window.onerror路由是不可能的。关于如何解决这个问题的任何建议?

提前致谢。

1 个答案:

答案 0 :(得分:0)

没有可靠的全局错误处理程序。只需将startup / shutdowninstall / uninstall)包裹在try-catch块中。您可能还想包装全局语句。

try {
  // do some fancy initialization... But you really shouldn't at the global scope.
}
catch (ex) {
  // handle/log error, e.g.
  Components.utils.reportError(ex);
}

function startup() {
  try {
    // Run
  }
  catch (ex) {
    // handle/log error, e.g.
    Components.utils.reportError(ex);
  }
}
function shutdown() …
// etc.

扩展管理器无论如何都会使用你的bootstrap.js记录失败(参见extensions.logging.enabled首选项)。

除此之外:SDK加载项可以使用chrome module来获取对低级别内容的访问权。

相关问题