Saturday, July 3, 2010

TRY CATCH in SQL Server

BEGIN TRY

DECLARE @DIVIDEBYZERO INT
SET @DIVIDEBYZERO = 100
SET @DIVIDEBYZERO=@DIVIDEBYZERO/0

END TRY
BEGIN CATCH
PRINT ERROR_NUMBER() -- RETURNS THE ERROR NUMBER
PRINT ERROR_MESSAGE() -- RETURNS THE ACTUAL ERROR MESSAGE
PRINT ERROR_LINE() -- RETURNS THE LINE NUMBER AT WHICH ERROR OCCURS
PRINT ERROR_PROCEDURE()-- RETURNS THE PROCEDURE IN WHICH THE ERROR OCCURS
END CATCH

No comments: