title: Using promises - Logging stack trace in fail handler
body: <p>I am rather new to nodejs so I will explain in a bit more detail what I am trying to do.</p>
  
  <p>I have a webserver. If a request fails I want to log the stack trace of that exception, but deliver a error page and not crash the server.</p>
  
  <p>As an example, the function handling the requests:</p>
  
  <pre><code>var Q = require('q');
  
  var requestHandler = function () {
      // Here I get the data etc. that was requested. As this is not important, just a dummy here
      Q.resolve()
          // Now I answer the request
          .then(function (data) {
              // Dummy Code representing the sending of a response
              console.log('sending response …');
              console.log('oh no! an exception');
              // Now an Exception occurs
              throw new Error('You did something wrong!');
          })
          // If there was any error, show the error page instead
          .fail(function (err) {
              // Dummy Code representing the sending of the error page
              console.log('sending error page');
              // Additionally I want to write the error into a log file
              console.error('You had an error: ', err);
          })
          // If there was an error in the .fail-handler, I deserve the server to crash
          .done();
  };
  
  // A request comes in, I want to call my handler
  requestHandler();
  </code></pre>
  
  <p>The console's output:</p>
  
  <pre><code>sending response …
  oh no! an exception
  sending error page
  You had an error:  [Error: You did something wrong!]
  </code></pre>
  
  <p>I can't see a way to access the stack trace. But when I throw an exception in the .fail-handler (or just omit the complete .fail-handler), I get a stack trace on the console (but I'd have to restart the server).</p>
  
  <p>So I guess my question is:</p>
  
  <p><strong>How do I access the stack trace in a promise fail handler?</strong></p>
  
  <p><strong>EDIT</strong>: Any tips on how to improve the explanation are welcome, of course. If I didn't make myself clear, please let me know.</p>