title: How can I catch JSON parsing errors in JQuery?
body: <p>In the following code, if the JSON I am trying to read in has a slight syntax error somewhere, then it simply doesn't say anything, I can't find any error shown in Chrome or Firefox which is telling me that it cannot parse the JSON field. Even this try/catch doesn't work.</p>
  
  <p>How can I get my code to do something specific if the JSON cannot be parsed?</p>
  
  <pre><code>function init() {
      elemFront = $('div.flashcard div.bodyFront');
      elemBack = $('div.flashcard div.bodyBack');
      console.log('before');
      try {
          console.log('inside try');
          $.getJSON('data.txt', function(jsonResult) {
              console.log(jsonResult);
          });
      } 
      catch(err) {
          console.log('error');
      }
      console.log('after');
  }
  </code></pre>
  
  <h2>Addendum</h2>
  
  <p>Thanks @sagi, that worked, here's the code that catches syntax issues with JSON data:</p>
  
  <pre><code>$.get('data.txt', {}, function(data, response){
      var jsonResult;
      try {
          jsonResult = JSON.parse(data);
      }
      catch (e) {
          $('div.header').html('&lt;span style="color:red"&gt;cannot load data because: "'+e+'"&lt;/span&gt;');
      };
      $('div.bodyFront').html(jsonResult['one']);
  });
  </code></pre>