Hi,
I would like to handle error severity in catch block for stored proc
ERROR_SEVERITY() is used but its returns no like 16, and so, but I need to display text which indicate corresponding error
Thank you
Hi,
I would like to handle error severity in catch block for stored proc
ERROR_SEVERITY() is used but its returns no like 16, and so, but I need to display text which indicate corresponding error
Thank you
Know the answer? Post it. Somebody with the same question will find it here.

Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kirtesh ShahRank #250 · 10K reputationPosted Nov 19, 2021, 12:11 AM EST
Hi, You can use ERROR_MESSAGE() to display error message with severity. See below code for more details,
BEGIN TRY
-- Generate a divide-by-zero error.
SELECT 1/0;
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;
END CATCH;
GO
Result
-----------
(0 row(s) affected)
ErrorNumber ErrorSeverity ErrorState ErrorProcedure ErrorLine ErrorMessage
----------- ------------- ----------- --------------- ----------- ----------------------------------
8134 16 1 NULL 4 Divide by zero error encountered.
(1 row(s) affected)
Jignesh KumarRank #91 · 22.9K reputationPosted Nov 19, 2021, 1:15 AM EST
Vinitha TRank #8,005 · 230 reputationPosted Nov 22, 2021, 9:51 AM EST
Vikas PanwarRank #1,447 · 1.1K reputationPosted Nov 18, 2021, 11:53 PM EST