CREATE PROCEDURE [dbo].[SP_RaiseError] AS DECLARE @errmsg nvarchar(max), @errline int, @severity int, @state int BEGIN TRY RAISERROR ('Terrible Error', 18, 1); -- Force and Error END TRY BEGIN CATCH PRINT 'In Catch Block' IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION SELECT @errmsg= ERROR_MESSAGE(), @errline=ERROR_LINE(), @severity=ERROR_SEVERITY(), @state=ERROR_STATE() SELECT @errmsg = CONCAT('Msg : ' , ERROR_MESSAGE(), ' @ Line ' , ERROR_LINE() , ' - ' , 'Error loading the table') END CATCH IF (@errmsg != '') --BEGIN -- PRINT 'In Error'; --INSERT INTO [dbo].[SY_B2BEvent] (Source, Event, TrackingRef, Status,Reason) VALUES('BG', 'Test', '99999', 'FAILED', 'Testing'); THROW 50000, @errmsg, 1; --END GO