The catch with try...catch

http://weblog.bocoup.com/ http://benalman.com/

by Ben Alman

JavaScript

var results = [];
var e = 1;

// No exception is thrown here.
try { } catch(e) { }

// 1. In every browser, e is 1.
results.push(e);

function test() {
  // No exception is thrown here.
  try { } catch(e) { }

  // 2. In IE, e is undefined. In other browsers, e is 1.
  results.push(e);

  // This should change the global `e`, but it doesn't in IE.
  e = 2;
}

test();

// 3. In IE, e is 1. In other browsers, e is 2.
results.push(e);

// The should output 1,1,2
document.write(results);