Sample Header Ad - 728x90

What is the point of TRY CATCH block when XACT_ABORT is turned ON?

15 votes
3 answers
9336 views
Code sample with XACT_ABORT_ON: SET XACT_ABORT_ON; BEGIN TRY BEGIN TRANSACTION //do multiple lines of sql here COMMIT TRANSACTION END TRY BEGIN CATCH IF (@@TRANCOUNT > 0) ROLLBACK; //may be print/log/throw error END CATCH Since XACT ABORT is ON, any error will automatically rollback the transaction. So what purpose does the TRY CATCH block serve?
Asked by variable (3590 rep)
Feb 1, 2022, 06:10 AM
Last activity: Sep 20, 2025, 02:18 AM