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