title: $.ajax error cannot catch thrown exception from php
body: <pre><code>$.ajax({
      type: "POST",
      url: "functions/add_vendor.php",
      data:
      {
          vendor_info_json : vendor_info_json
      },
      success:function(result)
      {
          alert('Successfully Done.')
          location.reload();
      },
      error: function(jqXHR, textStatus, errorThrown){
          alert('Error Message: '+ textStatus);
          alert('HTTP Error: '+ errorThrown);
      }
  })
  </code></pre>
  
  <p>This is the jquery code I'm working on. And the following is the add_vendor.php file being called.</p>
  
  <pre><code>&lt;?php
  include_once('../models/VENDOR_DB_MANAGER.php');
  
  $vendor_info_json = $_REQUEST["vendor_info_json"];
  $DB = new VENDOR_DB_MANAGER();
  $DB-&gt;connectTo('BBY');
  try
  {
              //This ALWAYS returns false to test the code.
      if($DB-&gt;insertDataToTable('mfVendor', $vendor_info_json))
      {
          $DB-&gt;disconnect();
  
          header('Content-Type: application/json');
          $data = json_encode($result);
          echo $data;
      }
      else
      {
          throw new Exception("Error has been detected.");
  
      }
  }
  catch (Exception $e)
  {
      header("HTTP/1.1 500 Internal Server Error");
              echo "Exception occurred: " . $e-&gt;getMessage();
  }
  ?&gt;
  </code></pre>
  
  <p>Ok, That 'if($DB->insertDataToTable('mfVendor', $vendor_info_json))' part always is false to test $.ajax's error handling code. No matter what I do, error: callback is not working even if the php code throws an exception all the time.</p>
  
  <p>What are the problems I'm missing here?  :(</p>