title: How to get resolved value/rejected error in finally block?
body: <p>Using the Q.js Javascript promise library, how can I get the resolved value/rejected error object in the finally block. Basically I want to execute common code in the finally block with the resolved data which was passed to the then block.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var q = require('Q');
  
  var defer = q.defer();
  
  setTimeout(function () {
      console.log("----------------------------------");
  
      promise2 = defer.promise;
      var t = promise2.then(function (value) {
          console.log('defer then =&gt; ' + value);
      })
      .catch(function (err) {
          console.log('defer catch =&gt; ' + err);
      })
      .finally(function (data) {
          console.log('function pro1 : ' + defer);
          // console.log('defer finally(resolved value) =&gt; ' + data); // how to get 123 here
          // console.log('defer finally(error) =&gt; ' + data); // how to get 'Error occurred.' here
          doSomething(data);
      })
  
      setTimeout(function () {
          console.log('after2: ' + t);
      },2000)
  
      defer.resolve('123');
      defer.reject('Error occurred.');
  },10);</code></pre>
  </div>
  </div>
  </p>