title: Throw custom errors async/await try-catch
body: <p>Let's say I have a function like this - </p>
  
  <pre><code>doSomeOperation = async () =&gt; {
    try {
      let result = await DoSomething.mightCauseException();
      if (result.invalidState) {
        throw new Error("Invalid State error");
      }
  
      return result;
    } catch (error) {
      ExceptionLogger.log(error);
      throw new Error("Error performing operation");
    }
  };
  </code></pre>
  
  <p>Here the <code>DoSomething.mightCauseException</code> is an asynchronous call that might cause an exception and I'm using <code>try..catch</code> to handle it. But then using the result obtained, I might decide that I need to tell the caller of <code>doSomeOperation</code> that the operation has failed with a certain reason.</p>
  
  <p>In the above function, the <code>Error</code> I'm throwing is caught by the <code>catch</code> block and only a generic <code>Error</code> gets thrown back to the caller of <code>doSomeOperation</code>.</p>
  
  <p>Caller of <code>doSomeOperation</code> might be doing something like this - </p>
  
  <pre><code>doSomeOperation()
    .then((result) =&gt; console.log("Success"))
    .catch((error) =&gt; console.log("Failed", error.message))
  </code></pre>
  
  <p>My custom error never gets here.</p>
  
  <p>This pattern can be used when building Express apps. The route handler would call some function which might want to fail in different ways and let the client know why it failed.</p>
  
  <p>I'm wondering how this can be done? Is there any other pattern to follow here? Thanks!</p>