title: Javascript try/catch scope
body: <p>I'm writing a code which is making Ajax request to a server. I'm using try/catch for error handling, outside the request, as you can see below. The search method is sending the request to the server, and if it can read the results, it calls the callback function.</p>
  
  <p>I'm asking this: since ajax requests are asynchronous, if there is an error inside the callback(not inside the search method), would it fall into the outer catch block or do I need another try/catch in the callback function?</p>
  
  <pre><code>try {
      service.search(function () {
          var entries = service.getEntries();
          $.each(entries, function (index, content) {
              var cat = {
                  // those may throw exceptions, too
                  name: content.get("category"),
                  path: content.getPath()
              };
              categories.push(cat); // defined somewhere else.
          });
          if (categories.length &lt; totalResults) {
              // A method call may throw exception
          } else if (typeof loadCallback === 'function') {
              // Done.
          }
      });
  } catch (e) {
  
  }
  </code></pre>