Check out example codes for "c# sql duplicate key exception". It will help you in understanding the concepts better.

Code Example 1

try
{
    // Try to insert
}
catch (SqlException exception)
{
    if (exception.Number == 2601) // Cannot insert duplicate key row in object error
    {
        // Handle duplicate key error
        return;                  
    }
    else
        throw; // Throw exception if this exception is unexpected
}

Learn ReactJs, React Native from akashmittal.com