"use strict";
/**
* @namespace Exceptions
* @desc Set of some useful exceptions.
* @author Kozalo <kozalo@yandex.ru>
* @copyright Kozalo.Ru, 2016
*/
let Exceptions = {
/**
* Returns a complete string to throw an exception.
* @memberof Exceptions
* @private
* @ignore
* @param {string} error The type of an exception.
* @param {Object?} argument
* @param {string?} message
* @returns {string}
*/
_genericException: function(error, argument, message) {
if (error === undefined)
throw '[Exception module] An internal error has occured (the type of an error is undefined)'
if (argument === undefined)
return error + '!';
else if (message === undefined)
return error + ': ' + argument + '!';
else
return error + ': ' + argument + '! ' + message;
},
/**
* Adds public methods for a client to throw exceptions into the Exceptions object.
* @memberof Exceptions
* @ignore
* @private
*/
_inflateExceptionsList: function() {
this.wrongArgument = function(argument, message) { return this._genericException('Wrong argument', argument, message); };
this.missingArgument = function(argument, message) { return this._genericException('Missing argument', argument, message); };
this.notImplementedYet = function() { return this._genericException('Not implemented yet'); };
this.abstractClass = function() { return this._genericException('You cannot create an instance of the abstract class'); };
}
};
Exceptions._inflateExceptionsList();