title: Catching specific exception
body: <p>How can I catch specific exception using c# ? <br>
  In my database there is unique index on some columns.<br>
  when user inserts duplicate record this exception has been throw :</p>
  
  <blockquote>
    <p>Cannot insert duplicate key row in
    object 'dbo.<em>BillIdentity' with unique
    index 'IX</em>_BillIdentity'. The
    statement has been terminated.</p>
  </blockquote>
  
  <p>How can I catch this exception? <br>
  Currently I am checking using this code :</p>
  
  <pre><code> catch (Exception ex) {
      if (ex.Message.Contains("Cannot insert duplicate key row in object 'dbo._BillIdentity' with unique index 'IX__BillIdentity")) {
          string ScriptKey = "$(function() {ShowMessage('Error');});";
          ScriptManager.RegisterStartupScript(Page, GetType(), "script", ScriptKey, true);
      }
  }
  </code></pre>
  
  <p>I think its bad smell code.<br>
  Is there any better way?</p>