设置全局PhantomJS错误处理程序

时间:2015-08-07 10:18:05

标签: javascript error-handling phantomjs

以下代码来自phantomjs cookbook。我想收到以下消息“[PHANTOMJS ERROR] Error: Gremlins fed after midnight.” 但它不起作用;它退出时没有记录任何东西:

以下是代码:

phantom.onError = function(message, trace) {
  console.error('[PHANTOMJS ERROR] ' + message);
  trace.forEach(function(t) {
    console.error(' >> [' + t.line + '] ' +
      (t.function ? '[' + t.function + '] ' : '') +
      t.file || t.sourceURL);
  });
  phantom.exit(1);
};

function doSomeErrorProneStuff() {
  throw new Error('Gremlins fed after midnight.');
}

doSomeErrorProneStuff();
console.log('Exiting cleanly.');
phantom.exit(0);

有什么东西被弃用了吗?

0 个答案:

没有答案
相关问题