title: How can you both throw an Error and return a value from a Javascript function
body: <p>What is the cleanest way to both throw an error and return a value from a Javascript function?</p>
  
  <p>Here's one proposed approach as a starting point:</p>
  
  <pre><code>(e, v) =&gt; {
     setTimeout(() =&gt; { throw(e) }, 0);
     return v; 
  }
  </code></pre>
  
  <p>Here's a runnable snippet to demonstrate further:</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>var val = ((e, v) =&gt; {
     setTimeout(() =&gt; { throw(e) }, 0); // will throw in console
     return v; 
  })('errMSG', 1)
  
  
  alert(val); // 1 </code></pre>
  </div>
  </div>
  </p>