CREATE PROCEDURE dbo.usp_RethrowError
AS
BEGIN
  -- return if not an error
  IF ERROR_NUMBER() IS NULL 
    RETURN;

  DECLARE 
    @ErrorMessage   NVARCHAR(4000), 
    @ErrorNumber    INT, 
    @ErrorSeverity  INT, 
    @ErrorState     INT, 
    @ErrorLine      INT,
    @ErrorProcedure NVARCHAR(256);    

  SELECT
    @ErrorNumber = ERROR_NUMBER(), 
    @ErrorSeverity = ERROR_SEVERITY(), 
    @ErrorState = ERROR_STATE(), 
    @ErrorLine = ERROR_LINE(),
    @ErrorProcedure = ISNULL(ERROR_PROCEDURE(), '-'); 

  -- Print error message
  SELECT @ErrorMessage = 
    N'Error %d, Level %d, State %d, Procedure %s, Line %d, ' +
    N'Message: ' + ERROR_MESSAGE();

  RAISERROR
    (
     @ErrorMessage,
     @ErrorSeverity,
     1,			-- to prevent error in raiserror
     @ErrorNumber,
     @ErrorSeverity,
     @ErrorState,
     @ErrorProcedure,
     @ErrorLine
     );
END
GO


  -- Raise an error as close to the original as possible
