michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, you can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var EXPORTED_SYMBOLS = ['BaseError', michael@0: 'ApplicationQuitError', michael@0: 'AssertionError', michael@0: 'TimeoutError']; michael@0: michael@0: michael@0: /** michael@0: * Creates a new instance of a base error michael@0: * michael@0: * @class Represents the base for custom errors michael@0: * @param {string} [aMessage=Error().message] michael@0: * The error message to show michael@0: * @param {string} [aFileName=Error().fileName] michael@0: * The file name where the error has been raised michael@0: * @param {string} [aLineNumber=Error().lineNumber] michael@0: * The line number of the file where the error has been raised michael@0: * @param {string} [aFunctionName=undefined] michael@0: * The function name in which the error has been raised michael@0: */ michael@0: function BaseError(aMessage, aFileName, aLineNumber, aFunctionName) { michael@0: this.name = this.constructor.name; michael@0: michael@0: var err = new Error(); michael@0: if (err.stack) { michael@0: this.stack = err.stack; michael@0: } michael@0: michael@0: this.message = aMessage || err.message; michael@0: this.fileName = aFileName || err.fileName; michael@0: this.lineNumber = aLineNumber || err.lineNumber; michael@0: this.functionName = aFunctionName; michael@0: } michael@0: michael@0: michael@0: /** michael@0: * Creates a new instance of an application quit error used by Mozmill to michael@0: * indicate that the application is going to shutdown michael@0: * michael@0: * @class Represents an error object thrown when the application is going to shutdown michael@0: * @param {string} [aMessage=Error().message] michael@0: * The error message to show michael@0: * @param {string} [aFileName=Error().fileName] michael@0: * The file name where the error has been raised michael@0: * @param {string} [aLineNumber=Error().lineNumber] michael@0: * The line number of the file where the error has been raised michael@0: * @param {string} [aFunctionName=undefined] michael@0: * The function name in which the error has been raised michael@0: */ michael@0: function ApplicationQuitError(aMessage, aFileName, aLineNumber, aFunctionName) { michael@0: BaseError.apply(this, arguments); michael@0: } michael@0: michael@0: ApplicationQuitError.prototype = Object.create(BaseError.prototype, { michael@0: constructor : { value : ApplicationQuitError } michael@0: }); michael@0: michael@0: michael@0: /** michael@0: * Creates a new instance of an assertion error michael@0: * michael@0: * @class Represents an error object thrown by failing assertions michael@0: * @param {string} [aMessage=Error().message] michael@0: * The error message to show michael@0: * @param {string} [aFileName=Error().fileName] michael@0: * The file name where the error has been raised michael@0: * @param {string} [aLineNumber=Error().lineNumber] michael@0: * The line number of the file where the error has been raised michael@0: * @param {string} [aFunctionName=undefined] michael@0: * The function name in which the error has been raised michael@0: */ michael@0: function AssertionError(aMessage, aFileName, aLineNumber, aFunctionName) { michael@0: BaseError.apply(this, arguments); michael@0: } michael@0: michael@0: AssertionError.prototype = Object.create(BaseError.prototype, { michael@0: constructor : { value : AssertionError } michael@0: }); michael@0: michael@0: /** michael@0: * Creates a new instance of a timeout error michael@0: * michael@0: * @class Represents an error object thrown by failing assertions michael@0: * @param {string} [aMessage=Error().message] michael@0: * The error message to show michael@0: * @param {string} [aFileName=Error().fileName] michael@0: * The file name where the error has been raised michael@0: * @param {string} [aLineNumber=Error().lineNumber] michael@0: * The line number of the file where the error has been raised michael@0: * @param {string} [aFunctionName=undefined] michael@0: * The function name in which the error has been raised michael@0: */ michael@0: function TimeoutError(aMessage, aFileName, aLineNumber, aFunctionName) { michael@0: AssertionError.apply(this, arguments); michael@0: } michael@0: michael@0: TimeoutError.prototype = Object.create(AssertionError.prototype, { michael@0: constructor : { value : TimeoutError } michael@0: });