Created
October 22, 2024 14:42
SQL try catch transaction block template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN TRY | |
BEGIN TRANSACTION | |
-- DO STUFF | |
ROLLBACK TRANSACTION --ROLLBACK COMMIT | |
END TRY | |
BEGIN CATCH | |
IF @@TRANCOUNT > 0 | |
BEGIN | |
ROLLBACK TRANSACTION | |
END | |
DECLARE @ErrorMessage NVARCHAR(4000) | |
DECLARE @ErrorSeverity INT | |
DECLARE @ErrorState INT | |
SELECT @ErrorMessage = ERROR_MESSAGE(), @ErrorSeverity = ERROR_SEVERITY(),@ErrorState = ERROR_STATE() | |
RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState) | |
END CATCH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment