CREATE PROCEDURE [dbo].[uspDoSomething]
 AS
 BEGIN
 
	SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
	SET NOCOUNT ON;
	

	BEGIN TRY

		-- Code Here

		RETURN 0 -- ok
		
	END TRY
	BEGIN CATCH
	
		/********************************************/
        /* Throw Error                              */ 
        /********************************************/
   
		DECLARE
		@iSEVERITY             INT ,            /* User set severity level      */
		@iSTATE                INT ,            /* Parameter in RAISERROR       */
		@vcErrorMsg            VARCHAR(255);    /* Error Message                */
			
        SELECT  @vcErrorMsg = ERROR_PROCEDURE() + 
					N' | SQL Error ' + CAST(ERROR_NUMBER() AS NVARCHAR(10)) +
					N' at line ' + CAST(ERROR_LINE() AS VARCHAR(10)) + '. ' + ERROR_MESSAGE(),
						
                @iSEVERITY  = ERROR_SEVERITY(),
                @iSTATE     = ERROR_STATE()    
            
        
        RAISERROR(@vcErrorMsg,@iSEVERITY,@iSTATE)
		RETURN(-1);
		
	END CATCH;

	
 END
 GO
 
Last modified: July 12, 2019

Author

Comments

Write a Reply or Comment