title: What happens here? SQL Server - XACT_ABORT ON + @@ERROR Checking . .
body: <p>What happens with this type of scenario?</p>
  
  <pre><code>SET XACT_ABORT ON
  
  BEGIN TRANSACTION
  
      ---DO SOMETHING HERE THAT CAUSES AN ERROR
  
  COMMIT TRANSACTION
  
  if @@error != 0
  raiserror('SP failed. Step 7.', 20, -1) with log GO
  </code></pre>
  
  <p>My guess is that because <code>XACT_ABORT</code> is <code>ON</code> the <code>COMMIT TRANSACTION</code> never happens (because the whole thing is rolled back and terminated), and neither does the last statement (checking for <code>@@error</code> and then calling <code>raiseerror</code>).</p>