CREATE PROC dbo.proc1
AS
SET XACT_ABORT ON;
BEGIN TRY
BEGIN TRAN
--body;
COMMIT
END TRY
BEGIN CATCH
DECLARE
@ErrorNumber int
,@ErrorSeverity int
,@ErrorState int
,@ErrorMessage nvarchar(2048);
IF @@TRANCOUNT > 0 ROLLBACK;
SELECT
@ErrorNumber = ERROR_NUMBER()
,@ErrorSeverity = ERROR_SEVERITY()
,@ErrorState = ERROR_STATE()
,@ErrorMessage = ERROR_MESSAGE();
RAISERROR('Error number %d caught: %s', @ErrorSeverity, @ErrorState, @ErrorNumber, @ErrorMessage);
END CATCH
GO
标签:BEGIN,ErrorState,示例,int,ErrorMessage,ABORT,ERROR,XACT,ErrorNumber From: https://www.cnblogs.com/jizhong/p/17640237.html