0

Is there any way to get the original error thrown by the evaluated code? I have a simple benchmark suite similar to the one bellow, nothing special.

var suite = new Benchmark.Suite;
    ...

suite.add('Collection Add', function () {
        collection.add(someArguments);
    })
    .on('cycle', function (event) {
        console.log(String(event.target));
    })
    .on('error', function (event) {
        console.log(event);
    })
    .run({'async': true});

The function that is benchmarked trows an error when it receives improper arguments. While setting up the benchmark this happens quite often.

My issue is that, instead of getting the exception raised by the benchmarked code, I get some other error which leaves me with no clue of why the tested code fails. I could try to run it once before the suite, just to check for thrown errors, however I find this to be a time consuming inconvenience.

error: ReferenceError: collection is not defined at Benchmark.define.amd.uid14507863...
Adrian Moisa
  • 3,923
  • 7
  • 41
  • 66

1 Answers1

0

I think you should use callbacks function to handle errors. Add console.log after .run() function:

.catch(function(err) { 
    console.log(err);
});
Wasiq Muhammad
  • 3,080
  • 3
  • 16
  • 29
  • I'm not sure if I am doing it right: `.run({'async': true}).catch(function(err){ console.log(err)});`. Throws another error: `suite.add(...).add(...).add(...).on(...).on(...).on(...).run(...).catch is not a function` Looks like it's not part of the benchmark.js api. – Adrian Moisa Dec 22 '15 at 12:40
  • I think benchmark.js library not used catch this call back function.you should refer to their documentation there must be some err handling callback functions available – Wasiq Muhammad Dec 22 '15 at 12:49