Components.utils.reportError
From MDC
Components.utils.reportError reports a JavaScript Error object to the Error Console, and returns. It is meant for use in exception handler blocks which want to "eat" an exception, but still want to report it to the console.
It must be called with one parameter, usually an object which was caught by an exception handler. If it is not a JavaScript error object, the parameter is converted to a string and reported as a new error. This means you can use Components.utils.reportError to report debugging messages to the Error Console, just like dump() can be used to print messages to the native console.
However you should use nsIConsoleService for logging, as it logs the messages with normal severity, unlike reportError.
function myDump(aMessage) {
var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
.getService(Components.interfaces.nsIConsoleService);
consoleService.logStringMessage("My component: " + aMessage);
}
[edit] Examples
Usage in an exception handler:
try {
this.could.raise.an.exception;
} catch(e) {
Components.utils.reportError(e); // report the error and continue execution
}
Printing debugging messages to the Error Console:
Components.utils.reportError("init() called");