title: JS Promises - Why am I seeing the UnhandledPromiseRejectionWarning and DeprecationWarning?
body: <p>I am getting to grips with promises and how to set them up, however I can't see why node thinks my promise is unhandled when it comes to errors... Can somebody please explain?</p>
  
  <p><strong>My simple code</strong></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>    // Setting up the Promise
      function add(x, y) {
          return new Promise((response, reject) =&gt; {
              // Simple conditional (not perfect, but it just proves a point)
              if(x !== null &amp;&amp; y !== null) {
                  // I know I could have done 'response(x + y)', but I wanted 
                  // to console.log the result also
                  var calc = x + y
                  response(calc)
                  console.log('Calculation: ' + x + ' + ' + y + ' = ' + calc)
              } else {
                  // My console does not throw this error?
                  reject('One of the inputs was null')
              }
          })
      }
      
      // Function using the Promise
      function calc() {
          add(1, 3)
              .then(res =&gt; add(res, 3))
              .then(res =&gt; add(res, null))
              .then(res =&gt; console.log('Final result: '+res))
              .catch(err =&gt; {
                  // This error is thrown in console
                  throw new Error('Something went horribly wrong')
              })
      }
      
      // Run the code
      calc();</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>Update</strong></p>
  
  <p>I originally posted the 'reject' with a thrown error, of which I understand needs to be caught.</p>
  
  <p>I also want to understand why the string in the 'reject' is not seen in my console?</p>
  
  <p>Console output:</p>
  
  <pre><code>Calculation: 1 + 3 = 4
  Calculation: 4 + 3 = 7
  (node:61950) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Something went horribly wrong
  (node:61950) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  </code></pre>