title: How can I throw an exception and add in my own message containing a key and a value?
body: <p>I have methods that look like this:</p>
  
  <pre><code>public IDictionary&lt;string, string&gt; Delete(Account account)
  {
      try { _accountRepository.Delete(account); }
      catch { _errors.Add("", "Error when deleting account"); }
      return _errors;
  }
  
  public IDictionary&lt;string, string&gt; ValidateNoDuplicate(Account ac)
  {
      var accounts = GetAccounts(ac.PartitionKey);
      if (accounts.Any(b =&gt; b.Title.Equals(ac.Title) &amp;&amp;
                              !b.RowKey.Equals(ac.RowKey)))
          _errors.Add("Account.Title", "Duplicate");
      return _errors;
  }
  </code></pre>
  
  <p>I would like to change this method so that it returns a bool and so it throws an exception if there is an error instead of:</p>
  
  <pre><code>_errors.Add("", "Error when deleting account");
  </code></pre>
  
  <p>Can someone explain to me how I can throw an exception and pass a message containing a key and a value. In this case the key would be <code>""</code> and the value would be <code>"Error when deleting account"</code>. </p>
  
  <p>Also in the method that calls this. How would I catch the exception?  </p>
  
  <p>Would it be necessary for me to make my own class and somehow throw an exception based on this class?</p>