title: SQL Server try catch inside a while loop statement.. will loop continue normally after exception?
body: <pre><code>WHILE(@InitialLoopValue &lt;= @FinalLoopValue)
  BEGIN  
      BEGIN TRY
          INSERT INTO Table(GCMRegId, Title, Url, OSType, NotificationType, IMEICode)     
              SELECT 
                  GCMRegId, @Title, @Url, SourceId, SubsMasterId, IMEICode 
              FROM 
                  #EligibleForNotification WITH(NOLOCK) 
              WHERE
                  Id = @InitialLoopValue                
      END TRY
      BEGIN CATCH
  
      END CATCH   
  
      SET @InitialLoopValue  = @InitialLoopValue  + 1     
  END
  </code></pre>
  
  <p>This is not the exact code but I have cut the minimum required code for this question. The <code>INSERT</code> statement inside the try block may sometimes cause a  primary key violation.</p>
  
  <p>I don't want loop to terminate by primary key violation. Instead I want it to continue without insert of particular row that is giving violation.</p>
  
  <p>Is it correct way of doing this?</p>