title: Why does try..catch not work with chrome.windows.get?
body: <p>I am trying to open a window by Chrome extension by browser action.</p>
  
  <pre><code>var wid = null;
  chrome.windows.get(wid, function(chromeWin) {
      chrome.windows.create({'url': 'https://google.com'}, function(chromeWin) {
              wid = chromeWin.id;
          }
      );
  });
  </code></pre>
  
  <p>To prevent multiple copies of the Window, I am trying to check window id. But if used first time, understandably, it throws error because <code>wid</code> is <code>null</code>.</p>
  
  <blockquote>
    <p>Error: Invocation of form windows.get(null, function) doesn't match definition windows.get(integer windowId, optional object getInfo, function callback)</p>
  </blockquote>
  
  <p>I tried to use <code>try..catch</code> block and in catch I am handling "<code>wid</code> is <code>null</code>" case.</p>
  
  <pre><code>try {
      var wid = null;
      chrome.windows.get(wid, function(chromeWin) {
          chrome.windows.create({'url': 'https://google.com'}, function(chromeWin) {
                  wid = chromeWin.id;
              }
          );
      });
  }
  catch(error) {
      chrome.windows.create({'url': 'https://google.com'}, function(chromeWin) {
              wid = chromeWin.id;
          }
      );      
  }
  </code></pre>
  
  <p>But <code>try..catch</code> is not catching the "<code>wid</code> is <code>null</code>" case. <strong>I know <code>if</code> clause may help for my experiment but I want to learn why <code>try</code> behaves this way.</strong></p>
  
  <p>Why is <code>try..catch</code> not caching the error and how can I open windows without copies in Chrome?</p>