Error Information Details in SQL SERVER

To know more about the error information, we can use the below mentioned functions

1. ERROR_NUMBER() returns the number of the error.
2. ERROR_SEVERITY() returns the severity.
3. ERROR_STATE() returns the error state number.
4. ERROR_PROCEDURE() returns the name of the stored procedure or trigger where the error occurred.
5. ERROR_LINE() returns the line number inside the routine that caused the error.
6. ERROR_MESSAGE() returns the complete text of the error message.


As discussed in my previous post the divide by zero error can be seen using the error information functions.

CREATE PROCEDURE GenerateDetailedException
AS
BEGIN
BEGIN TRY
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
END

Comments

Popular posts from this blog

Jesus - God Thinks of you.

ASP.NET 4.0 Feature - URL Routing

Tips on JQuery Intellisense in VS 2008