[英]Setting up a global error handler in a bootstrapped firefox extension
我正在為Firefox構建一個自舉擴展(因為我需要tcp套接字,所以不使用附加SDK)。 盡管我所有的IO調用等都受到try / catch的保護,但我還是希望有一個全局錯誤處理程序,以防萬一。 自舉擴展不能訪問window對象,因此window.onerror路由是不可能的。 關於如何解決這個問題有什么建議嗎?
提前致謝。
沒有可靠的全局錯誤處理程序。 只需將startup
/ shutdown
( install
/ 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
模塊來訪問低級內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.