22.8.10

Function related to exceptions in sql server

I happened to read an article on SQL Server exception. I found some of the useful functions which will be very useful to find the exception details like,

1. ERROR_NUMBER() - This function will provide your the exact error number.
2. ERROR_MESSAGE() - This function will provide the error message thrown
3. ERROR_LINE() - This function will provide you the exact line number where error occurs.
4. ERROR_PROCEDURE() - This function will provide your the procedure where error occurs.

BEGIN TRY BEGIN TRAN
DECLARE @dividebyzero INT
SET @dividebyzero = 100
SET @dividebyzero = @dividebyzero/0
COMMIT
END
TRY
BEGIN CATCH
PRINT ERROR_NUMBER()
PRINT ERROR_MESSAGE()
PRINT ERROR_LINE()
PRINT ERROR_PROCEDURE()
ROLLBack
END CATCH

Cheers,
Venkatesan Prabu .J

No comments:

Post a Comment