Error Functions in Sql Server.

Vishalneeraj-24503
Posted by Vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 710
Inside the CATCH block there are a number of specialized functions to return information about the error.
BEGIN TRY
SELECT [Second] = 1/0;
END TRY
BEGIN CATCH
SELECT [Error_Line] = ERROR_LINE(),
[Error_Number] = ERROR_NUMBER(),
[Error_Severity] = ERROR_SEVERITY(),
[Error_State] = ERROR_STATE()

SELECT [Error_Message] = ERROR_MESSAGE()
END CATCH


Output:-
(0 row(s) affected)

Error_Line Error_Number Error_Severity Error_State
----------- ------------ -------------- -----------
2 8134 16 1

(1 row(s) affected)

Error_Message
---------------------------------------------------
Divide by zero error encountered.

(1 row(s) affected)

Comments or Responses

Login to post response