News for hackers. Stuff that matters.
Re:Comparing Node.js Promises, Try/Catch, Angular Zone.js an... by eldude on Wednesday April 16, 2014 @01:13PM (#7599052)
A major limitation of using try/catch is that V8 will DEOPT your function call, which can be a 5-10x performance hit (to the current closure). The best way to avoid this is with a silly hack:

    function trycatchit(fn, that, args) {
      try {
        return fn.apply(that, args)
      } catch(e) {
       return e
      }
    }

    var value = trycatchit(fn, null, 'someValue')
    if (value instanceof Error) {
      ...
    }
Really though, you should just let co or whatever generator library you're using catch the error and rethrow it (or pass it to a callback) or be mindful to minimize your error handling.

[1] https://github.com/CrabDude/trycatch/blob/master/lib/trycatc...

There are no comments on this comment yet.