T-SQL Error Handling

Submitted by:David Villa

Date added:31 July, 2012

Category:SQL

Boiler Plate for T-Sql Error handling

Tags: error handling

Code Snippet:

    BEGIN TRY
BEGIN TRAN

COMMIT TRAN
END TRY

BEGIN CATCH
Declare @ErrorMessage varchar(2000) = (SELECT ERROR_MESSAGE())
Declare @ErrorSeverity int = (SELECT ERROR_SEVERITY())
Declare @ErrorState int = (SELECT ERROR_STATE())
ROLLBACK TRANSATION
RAISERROR(@ErrorMessage, @ErrorSeverity, @ErrorState)

END CATCH
 
 

Comments