@manhnguyenv

Welcome to my blog!

Stored return error message

April 26, 2018 23:34

Stored Procedure Return Error Message

DECLARE @ErrorMessage VARCHAR(MAX)
,@ErrorProcedure VARCHAR(255)
,@ErrorSeverity INT
,@ErrorState INT
,@ErrorLine INT

BEGIN TRY

--TODO:

END TRY

BEGIN CATCH
SELECT @ErrorMessage = ERROR_MESSAGE()
,@ErrorSeverity = ERROR_SEVERITY()
,@ErrorProcedure = ERROR_PROCEDURE()
,@ErrorState = ERROR_STATE()
,@ErrorLine = ERROR_LINE()

SET @ErrorMessage = 'Procedure: ' + @ErrorProcedure + ' ' + @ErrorMessage + ' Line: ' + CONVERT(VARCHAR(20), @ErrorLine)

RAISERROR (
@ErrorMessage
,@ErrorSeverity
,@ErrorState
)
END CATCH

Categories

Recent posts