Skip to content

Instantly share code, notes, and snippets.

@kusor
Created December 30, 2009 18:38
Show Gist options
  • Save kusor/266275 to your computer and use it in GitHub Desktop.
Save kusor/266275 to your computer and use it in GitHub Desktop.
Custom JavaScript Error
$ ./bin/js
js> function ResourceValidationError() {
Error.apply(this, arguments);
if (arguments.length >= 1) {
this.message = arguments[0];
}
}
js> ResourceValidationError.prototype = new Error();
Error
js> ResourceValidationError.prototype.constructor = ResourceValidationError;
function ResourceValidationError() {
Error.apply(this, arguments);
if (arguments.length >= 1) {
this.message = arguments[0];
}
}
js> ResourceValidationError.prototype.name = 'ResourceValidationError';
ResourceValidationError
js> try {
throw new ResourceValidationError('this.foo is required');
} catch(e) {
if (e.name == 'ResourceValidationError'){
e.message;
}
}
this.foo is required
js>
function ResourceValidationError() {
Error.apply(this, arguments);
if (arguments.length >= 1) {
this.message = arguments[0];
}
}
ResourceValidationError.prototype = new Error();
ResourceValidationError.prototype.constructor = ResourceValidationError;
ResourceValidationError.prototype.name = 'ResourceValidationError';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment