1
votes

I am building a bootstrapped extension for Firefox (not using the Add-on SDK since I need tcp sockets). Although all my IO calls etc. are protected by a try/catch, I want to have a global error handler just in case. Bootstrapped extensions do not have access to a window object so the window.onerror route is out of the question. Any suggestions as to how I can go about this?

Thanks in advance.

1

1 Answers

0
votes

There is no such thing as a reliable global error handler. Just wrap startup/shutdown (install/uninstall) in try-catch blocks. You may also want to wrap global statements.

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.

The extension manager will log failures with your bootstrap.js anyway (see the extensions.logging.enabled preference).

Aside: SDK add-ons can use the chrome module to gain access to low level stuff.