title: Try and Catch on TSQL - catch not catching
body: <p>I have a stored procedure that seems not to be logging its errors correctly.</p>
  
  <p>The code is erroring, but the catch block doesn't seem to be coming into effect.</p>
  
  <p>The try block is fairly long - but the erroring section is simple and comes rightat the end, so I've precis'd that.</p>
  
  <pre><code>BEGIN TRY 
  insert into tbl_X
  select * from #temp_tbl_Y
  
  RETURN 1
  END TRY
  
  BEGIN CATCH
      Insert Into ExtractsErrorLog
      SELECT 
      getdate() as ErrorDate 
      ,object_name(@@procid) as ProcedureName
      ,ERROR_NUMBER() as ErrorNumber
      ,ERROR_LINE() as ErrorLine
      ,ERROR_MESSAGE() as ErrorMessage
      ;
  DECLARE @errormessage as varchar(max);
  DECLARE @errorseverity as int;
  DECLARE @errorstate as int;
  
  set @errormessage = ERROR_MESSAGE();
  set @errorseverity = ERROR_SEVERITY();
  set @errorstate = ERROR_STATE();
  
   RAISERROR (@errormessage,
              @errorseverity,
              @errorstate
                 );
  
  
  END CATCH;
  </code></pre>
  
  <p>The error the proc is failing on is our old friend
  "Column name or number of supplied values does not match table definition."
  I've fixed that error - It was a dumb lazy mistake - but  I'm baffled why my error logging process didn't seem to be working - no row is being  inserted into my ExtractsErrorLog table.</p>