title: Pass custom message to catch error block with throw error
body: <p>I want to create custom error message and be able to read it in my catch block, how can I achieve this? I want to make erorMessage in catch block with the text that <code>throw Error</code> passes and be able to display custom error message. However when I try to log (err)</p>
  <pre class="lang-js prettyprint-override"><code>const password = &quot;test&quot;;
  const repeatPassword = &quot;test1&quot;;
  let errorMessage = &quot;&quot;;
  
  const handleSubmit = () =&gt; {
      if(password != repeatPassword) {
      throw Error(&quot;Passwords must match&quot;);
    }
    
    try {
      console.log(&quot;trying&quot;);
    } catch(err) {
      errorMessage = err;
      console.log(err);
    }
  }
  
  handleSubmit();
  </code></pre>
  <p>am I approaching this in wrong way?</p>