I am trying to convert an existing SQL script to have a try catch error system. Can anyone look it over and make sure I did it right? This SP will be called by other SPs to it is important to return to the calling script that an error happened so when I convert that one to try catch it will error out also.Original Script:CREATE PROC dbo.spAddSectionMenuItem @SectionID AS smallint, @MenuType AS char(5), @LinkRoute AS varchar(50), @LinkName AS varchar(50), @LinkTitle AS varchar(250)ASSET NOCOUNT ONSET XACT_ABORT ONDECLARE @ErrorNum intBEGIN TRANSACTIONIF NOT EXISTS (SELECT 1 FROM dbo.SectionMenuItems WHERE SectionID = @SectionID and MenuType = @MenuType)BEGIN INSERT INTO dbo.SectionMenuItems (SectionID, MenuType, LinkRoute, LinkName, LinkTitle) VALUES (@SectionID, @MenuType, @LinkRoute, @LinkName, @LinkTitle); SET @ErrorNum = @@ERROR;ENDif (@ErrorNum = 0)BEGIN COMMITENDELSEBEGIN ROLLBACKENDRETURN @ErrorNum
New script:CREATE PROC dbo.spAddSectionMenuItem @SectionID AS smallint, @MenuType AS char(5), @LinkRoute AS varchar(50), @LinkName AS varchar(50), @LinkTitle AS varchar(250)ASSET NOCOUNT ONSET XACT_ABORT ONDECLARE @ErrorNum intBEGIN TRY BEGIN TRANSACTION IF NOT EXISTS (SELECT 1 FROM dbo.SectionMenuItems WHERE SectionID = @SectionID and MenuType = @MenuType) BEGIN INSERT INTO dbo.SectionMenuItems (SectionID, MenuType, LinkRoute, LinkName, LinkTitle) VALUES (@SectionID, @MenuType, @LinkRoute, @LinkName, @LinkTitle); RETURN 0; END COMMITEND TRYBEGIN CATCH RETURN @@ERROR; ROLLBACKEND CATCH
-- If I get used to envying others...Those things about my self I pride will slowly fade away.-Stellvia