Error Handling in Sql Server.

CREATE PROCEDURE ErrorHandling
AS
SELECT * FROM aaa
GO

CREATE PROCEDURE ErrorHandling

BEGIN TRY
EXEC ErrorHandling
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() as ErrorNumber, --returns the number of the error.
ERROR_MESSAGE() as ErrorMessage, --returns the complete text of the error message.
ERROR_SEVERITY() as Severity, --returns the severity
ERROR_PROCEDURE() as SPName, --returns the name of the stored procedure or trigger where the error occurred.
ERROR_LINE() as ErrorLine, --returns the line number inside the routine that caused the error.
ERROR_STATE() as State; --returns the error state number
SELECT * FROM EMPLOYEE -- Can write a query here which will always be executed.
END CATCH


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: