title: exception handling for nodejs with q
body: <p>I am using Nodejs with Q for promises. Here <code>promise2</code> connects to cassandra server and inserts some data. But when database is down it returns with </p>
  
  <pre><code> {
    "innerErrors": {
      "127.0.0.1:9042": {
        "code": "ECONNREFUSED",
        "errno": "ECONNREFUSED",
        "syscall": "connect"
      }
    },
    "info": "Represents an error when a query cannot be performed because no host is available or could be reached by the driver.",
    "message": "All host(s) tried for query failed. First host tried, 127.0.0.1:9042: Error: connect ECONNREFUSED. See innerErrors."
  }
  </code></pre>
  
  <p>and correctly executes the <code>deferred.reject(err)</code>. But somehow it won't get caught in catch block in promise chain(app wont crash it will just continue).  However if promise1 which doesn't involve cassandra operation, rejects it, it will get caught in catch block. 
  How to catch this error ?</p>
  
  <p>Promise chain</p>
  
  <pre><code>promise1(someData)
  .then(function(result){
      return promise2();
   })
  .then(function(result){
      // deferred.resolve();
   })
  .catch(function(err){
      // deferred.reject(err);
  });
  </code></pre>
  
  <p><code>Promise2</code> implementation</p>
  
  <pre><code>boundary.client.execute(query,fieldValues,{prepare:isPrepare}, function(err,result){
          if(err){
            deferred.reject(err);
          }else{
              deferred.resolve(result);
          }
  </code></pre>