title: How to properly implement error handling in async/await case
body: <p>I use async/await ecma6 standard without any custom library.</p>
  
  <p>I don't get at the moment how I can properly catch and throw errors.
  I have multiple async/await functions and if somewhere down below an critical error happens I want to throw the error to the top and of all async functions and stop execution of the function.</p>
  
  <p>I tried to throw exceptions out of the async/await function and catch it in the target function but I get a error in node.js:</p>
  
  <pre><code>    this.basicAuthLogin= async function(user)
  {
      "use strict";
      const login = new Login(this.host, this.url, user, user.pw);
  
      //getSessionID throws error
      this.sessionID = getSessionID(result.request.response);
  }
  </code></pre>
  
  <blockquote>
    <p>(node:13964) UnhandledPromiseRejectionWarning: Unhandled promise
    rejection (rejection id: 1): Error: getSessionID response is undefined
    (node:13964) [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. Debugger attached.</p>
  </blockquote>
  
  <p>So it seems I am not allowed to throw exceptions out of async functions or even rethrow it in the catch block of the promise in node.js?</p>
  
  <p>So how do I get this working? 
  Am I supposed to catch the error in the async function and return the error in the promise and rethrow then out of the async function?</p>
  
  <pre><code>   this.basicAuthLogin= async function(user)
  {
      "use strict";
      const login = new Login(this.host, this.url, user, user.pw);
     try{
      //getSessionID throws error
      this.sessionID = getSessionID(result.request.response);
     } catch(err) { return err;}
  }
  </code></pre>
  
  <p>But this would mean that in my call stack from the first async function every function needs be async and I have to await the promise even though I don't really need it.</p>
  
  <p>I hope somebody can enlighten me.</p>
  
  <p>Regards
  Ruvi</p>
  
  <p>Edit basic call stack pseudo code:</p>
  
  <pre><code>   async startTest[arr]{
  
      for (var i = 0; i &lt; arr.length; i++)
      {
        try {
            await runStep(arr[i];
          } catch(err) { 
              console.log(err);
              break; 
          }
        }
      }
  
    async runStep(step)
    {
       try {
       var userIsValid = await validateUser(step.user);
       var req = buildRequest(step.request);
       var result = await sendRequest(req);
       var verify = verifyResult();
       } catch(err){ throw err;}
    }
  
    async validateUser(user)
    {
       //make checks
       //
       var result = await this.authenticate(parameter).catch(err =&gt; {throw err});
       userFound = true;
     }
  
    function authenticate(parameter) {
    //can throw async function
     basicAuthLogin(parameter).catch(err =&gt; {throw err};
  
     }
  
    function async basicAuthLogin(parameter()
    {
     try {
      //can throw  async function
        var result = await request(parameter);
        //can throw sync function
        this.sessionID = getSessionID(response);
        //can throw   sync function
        } catch(err) { throw err; }
     }
  </code></pre>