Posted By

amos24c on 10/25/11


Tagged

error tsql Handling


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

jstrawther


T-SQL Error Handling


 / Published in: SQL
 

Boiler Plate for T-Sql Error handling

  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  

You need to login to post a comment.