Created
October 20, 2015 12:08
-
-
Save tregusti/0b37804798a7634bc49c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function NotImplementedError(message) { | |
this.message = message || ""; | |
} | |
NotImplementedError.prototype = Object.create(Error.prototype, { | |
constructor: { value: NotImplementedError }, | |
name: { value: 'NotImplementedError' }, | |
stack: { get: function() { | |
return new Error().stack; | |
}}, | |
}); |
As an arrow function which exports:
/**
* @summary A error thrown when a method is defined but not implemented (yet).
* @param {any} message An additional message for the error.
*/
exports.NotImplementedError = (message) => {
/// <summary>The error thrown when the given function isn't implemented.</summary>
const sender = (new Error())
.stack
.split('\n')[2]
.replace(' at ', '');
this.message = `The method ${sender} isn't implemented.`;
// Append the message if given.
if (message) { this.message += ` Message: "${message}".`; }
let str = this.message;
while (str.indexOf(' ') > -1) {
str = str.replace(' ', ' ');
}
this.message = str;
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A little contribution:
Shows what method threw the Error.