title: How To Supress MySql.Data.MySqlClient.MySqlException Duplicate Entry
body: <p>So I have a database with a unique constraint of multiple columns. Obviously to prevent duplicates. When debugging my application, my console is absolutely filled with <code>MySql.Data.MySqlClient.MySqlException</code>s</p>
  
  <p>Is there a way to supress these as this is the intended function of the database? Catching the exception doesn't seem to do it. It will handle it based on my <code>catch(MySqlException e)</code> statement, but still shows the <code>MySql.Data.MySqlClient.MySqlException</code> in the console.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public void InsertNewTeamHistory(TeamHistoryRow teamHistoryRow)
      {
          //open connection
          if (this.OpenConnection)
          {
              try
              {
                  var query =
                      "INSERT INTO teamhistory(MatchURL, Date, TeamOne, TeamOneScore, TeamTwo, TeamTwoScore, Map, Event, Outcome) " +
                      "VALUES(?MatchURL, ?Date, ?TeamOne, ?TeamOneScore, ?TeamTwo, ?TeamTwoScore, ?Map, ?Event, ?Outcome)";
  
                  //create command and assign the query and connection from the constructor
                  using (var cmd = new MySqlCommand(query, _connection))
                  {
                      if (cmd.Connection.State == ConnectionState.Open)
                      {
                          cmd.Parameters.Add("?MatchURL", MySqlDbType.VarChar).Value = teamHistoryRow.MatchUrl;
                          cmd.Parameters.Add("?Date", MySqlDbType.Date).Value = teamHistoryRow.Date;
                          cmd.Parameters.Add("?TeamOne", MySqlDbType.VarChar).Value = teamHistoryRow.TeamOne;
                          cmd.Parameters.Add("?TeamOneScore", MySqlDbType.Int32).Value = teamHistoryRow.TeamOneScore;
                          cmd.Parameters.Add("?TeamTwo", MySqlDbType.VarChar).Value = teamHistoryRow.TeamTwo;
                          cmd.Parameters.Add("?TeamTwoScore", MySqlDbType.Int32).Value = teamHistoryRow.TeamTwoScore;
                          cmd.Parameters.Add("?Map", MySqlDbType.VarChar).Value = teamHistoryRow.Map;
                          cmd.Parameters.Add("?Event", MySqlDbType.VarChar).Value = teamHistoryRow.Event;
                          cmd.Parameters.Add("?Outcome", MySqlDbType.VarChar).Value = teamHistoryRow.Outcome;
  
                          //Execute command
                          cmd.ExecuteNonQuery();
  
                          //close connection
                          this.CloseConnection();
                      }
                      else
                      {
                          throw new Exception("Failed - Connection to the DB NOT open.");
                      }
                  }
              }
              catch (MySqlException e)
              {
                  switch (e.Number)
                  {
                      case 1062:
                          Console.WriteLine("Found Duplicate TeamHistoryRow, Not Inserting.");
                          break;
                      case 0:
                          Console.WriteLine("Well, we fucked up.");
                          break;
                      default:
                          throw;
                  }
              }
              finally
              {
                  try
                  {
                      this.CloseConnection();
                  }
                  catch (Exception ex)
                  {
                      Console.WriteLine(ex);
                  }
              }
          }
      }
  </code></pre>