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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.


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)

Vinitha TPosted Nov 22, 2021, 2:51 PM
Sachin SinghPosted Nov 19, 2021, 6:59 AM