title: Async/await requires promise to be caught?
body: <p>Spent a day debugging strange error. I'm not a master in using async/await, apparently, as this little example shows. I guess its counter-intuitive to me but I didn't expect the following:</p>
  
  <pre><code>var p = new Promise((resolve, reject) =&gt; {
     reject(new Error('some rainy days...'))
  })
  
  p
     .then(data =&gt; {console.info('data', data)})
     .catch(error =&gt; {console.error('inner error', error)})
     .finally(() =&gt; {console.info('inner done!')})
     .catch(error =&gt; {console.error('outer error', error)})
     .finally(() =&gt; {console.info('outer done!')})
  
  async function test (p) {
     try {
        let data = await p
        console.info('async data', data)
        return data
     } catch (error) {
        console.error('async error', error)
        throw error
     } finally {
        console.info('async is done!')
     }
  }
  
  test(p)
     .then(data =&gt; {console.info('test data', data)})
     .catch(error =&gt; {console.error('test error', error)})
     .finally(() =&gt; {console.info('test done!')})
  </code></pre>
  
  <p>The output is as follows:</p>
  
  <pre><code>inner error Error: some rainy days...
      at Promise (&lt;anonymous&gt;:2:11)
      at new Promise (&lt;anonymous&gt;)
      at &lt;anonymous&gt;:1:9
  inner done!
  async error Error: some rainy days...
      at Promise (&lt;anonymous&gt;:2:11)
      at new Promise (&lt;anonymous&gt;)
      at &lt;anonymous&gt;:1:9
  async is done!
  test error Error: some rainy days...
      at Promise (&lt;anonymous&gt;:2:11)
      at new Promise (&lt;anonymous&gt;)
      at &lt;anonymous&gt;:1:9
  test done!
  outer done!
  </code></pre>
  
  <p>The output is not unexpected. However, I did not expect to be required to use <code>.catch</code> prior and inside the <code>async</code> method. If I omit all <code>.catch</code>, <code>UnhandledPromiseRejectionWarning</code> will be thrown. Code is as follows:</p>
  
  <pre><code>var p = new Promise((resolve, reject) =&gt; {
     reject(new Error('some rainy days...'))
  })
  
  p
     .then(data =&gt; {console.info('data', data)})
     // .catch(error =&gt; {console.error('inner error', error)})
     .finally(() =&gt; {console.info('inner done!')})
     // .catch(error =&gt; {console.error('outer error', error)})
     .finally(() =&gt; {console.info('outer done!')})
  
  async function test (p) {
     try {
        let data = await p
        console.info('async data', data)
        return data
     } catch (error) {
        console.error('async error', error)
        throw error
     } finally {
        console.info('async is done!')
     }
  }
  
  test(p)
     .then(data =&gt; {console.info('test data', data)})
     .catch(error =&gt; {console.error('test error', error)})
     .finally(() =&gt; {console.info('test done!')})
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>async error Error: some rainy days...
      at Promise (&lt;anonymous&gt;:2:11)
      at new Promise (&lt;anonymous&gt;)
      at &lt;anonymous&gt;:1:9
  async is done!
  outer done!
  test error Error: some rainy days...
      at Promise (&lt;anonymous&gt;:2:11)
      at new Promise (&lt;anonymous&gt;)
      at &lt;anonymous&gt;:1:9
  test done!
  Uncaught (in promise) Error: some rainy days...
      at Promise (&lt;anonymous&gt;:2:11)
      at new Promise (&lt;anonymous&gt;)
      at &lt;anonymous&gt;:1:9
  </code></pre>
  
  <p>My expectation was that <code>await</code> would unwrap or catch and throw the error, which would be automatically caught inside <code>try/catch</code> block of the <code>async</code> function. Otherwise, I'm not sure what is the best way of handling parameters to an <code>async</code> method when some can be either promises or scalars.</p>
  
  <p>Obviously, I've got something terribly wrong! Would greatly appreciate if someone could set the record for me straight! </p>