T-SQL Error Handling


/ Published in: SQL
Save to your folder(s)

Boiler Plate for T-Sql Error handling


Copy this code and paste it in your HTML
  1. BEGIN TRY
  2. BEGIN TRAN
  3.  
  4.  
  5. COMMIT TRAN
  6. END TRY
  7.  
  8. BEGIN CATCH
  9. DECLARE @ErrorMessage VARCHAR(2000) = (SELECT ERROR_MESSAGE())
  10. DECLARE @ErrorSeverity INT = (SELECT ERROR_SEVERITY())
  11. DECLARE @ErrorState INT = (SELECT ERROR_STATE())
  12. ROLLBACK TRANSATION
  13. RAISERROR(@ErrorMessage, @ErrorSeverity, @ErrorState)
  14.  
  15. END CATCH

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.