Wednesday, October 8, 2008

Error Handling In Sql Server

Error_Number()

Returns the error number of the error that caused the CATCH block of a TRY…CATCH construct to be run in Sql Server. Return type of this function is int.


Error_Line()

Returns the line number at which an error occurred in Sql Server Stored Procedure..

Error_Message()
Returns the message text of the error that occured in Sql Server Stored Procedure.


Example :

BEGIN TRY
SELECT 1/0; --Divide by zero error
END TRY

BEGIN CATCH
SELECT ERROR_NUMBER() AS ErrNumber;
SELECT ERROR_LINE() AS ErrLine;
SELECT ERROR_MESSAGE() AS ErrorMessage;
END CATCH

No comments: