JS生成的Image HTML元素会抛出异常吗?

时间:2013-07-31 11:09:06

标签: javascript exception-handling

我在Facebook上找到了这个代码,其中有一个我不理解的尝试捕获。

fb_param是一个JS对象,其中唯一必需的属性是pixel_id,但该条件由if子句检查。

有谁能告诉我这段代码怎么会引发异常?

/*1375267557,179355677,JIT Construction: v893363,en_US*/

/**
 * Copyright Facebook Inc.
 *
 * Licensed under the Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 */
try {
  (function() {
    if (typeof fb_param != 'undefined' && fb_param.pixel_id) {
      var a = 'https://www.facebook.com/offsite_event.php',
        b = a + '?id=' + fb_param.pixel_id;
      if (fb_param.value) b += '&value=' + encodeURIComponent(fb_param.value);
      if (fb_param.currency) b += '&currency=' + encodeURIComponent(fb_param.currency);
      var c = new Image();
      c.src = b;
    }
  })();
} catch (e) {
  new Image().src = "http:\/\/www.facebook.com\/" + 'common/scribe_endpoint.php?c=jssdk_error&m=' + encodeURIComponent('{"error":"LOAD", "extra": {"name":"' + e.name + '","line":"' + (e.lineNumber || e.line) + '","script":"' + (e.fileName || e.sourceURL || e.script) + '","stack":"' + (e.stackTrace || e.stack) + '","message":"' + e.message + '"}}');
}

0 个答案:

没有答案