Skip to content

Instantly share code, notes, and snippets.

@braydonf
Last active August 29, 2015 14:10
Show Gist options
  • Save braydonf/b181026ee6d13976d10c to your computer and use it in GitHub Desktop.
Save braydonf/b181026ee6d13976d10c to your computer and use it in GitHub Desktop.
BuildErrors
var inherits = require('inherits');
var Point = function(){};
Point.Errors = {};
var defineErrors = function(base, specs){
specs.forEach(function(spec){
var e = function(message){
this.message = message || spec.message;
};
e.name = spec.name;
inherits(e, spec.inherits);
Object.defineProperty(base, spec.name, {
configurable: false,
value: e
});
});
};
var errors = [
{
name: 'InvalidY',
message: 'Invalid Y point for secp256k1 curve.',
inherits: TypeError
}
];
defineErrors(Point.Errors, errors);
var y = '847204eoneotffff';
try {
throw new Point.Errors.InvalidY('Invalid y: '+ y + ' for the secp256k1 curve.');
} catch(e){
if (e instanceof Point.Errors.InvalidY){
console.log(e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment