Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for (i = 0; i < len; i++) {
- try { this.example(arg[i]) }
- catch (e) { log(e) }
- }
- function ErrorCollection(msg) {
- this.name = 'ErrorCollection';
- this.message = msg || '';
- this.errors = [];
- }
- ErrorCollection.prototype = Object.create(Error.prototype);
- ErrorCollection.prototype.constructor = ErrorCollection;
- ErrorCollection.prototype.push = function (e) {
- return this.errors.push(e);
- }
- // ...
- var i, ec = new ErrorCollection();
- for (i = 0; i < 10; ++i) {
- try {
- throw new Error('Error ' + i);
- } catch (e) {
- ec.push(e);
- }
- }
- // do something with ec, e.g.
- if (ec.errors.length) {
- console.log(ec, ec.errors);
- throw ec;
- }
- var i, a = [];
- for (i = 0; i < arguments.length; ++i) {
- try { // assume everything will work
- this.example(arguments[i]);
- } catch (e) { // our assumption was wrong
- a.push({arg: i, val: arguments[i]});
- for (++i; i < arguments.length; ++i) { // loop from where we left off
- if (!this.valid_arg(arguments[i])) { // some costly test
- a.push({arg: i, val: arguments[i]});
- }
- }
- throw a; // throw the list of bad args up a level
- }
- }
Add Comment
Please, Sign In to add comment