Last active
August 29, 2015 14:10
-
-
Save braydonf/b181026ee6d13976d10c to your computer and use it in GitHub Desktop.
BuildErrors
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
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