Best way to insert error information from catch block in the table for stored procedure?
The below is what i use to catch errors and send it of to the developers. It generates a mail every time an error occurs

BEGIN CATCH  

(SELECT @Servername AS ServerName, 

 ERROR_NUMBER() AS ErrorNumber  

,ERROR_SEVERITY() AS ErrorSeverity  

,ERROR_STATE() AS ErrorState  

,ERROR_PROCEDURE() AS ErrorProcedure  

,ERROR_MESSAGE() AS ErrorMessage

INTO #ERROR )



/*************************************************************/  

/****************** HTML Preparation *************************/  

/*************************************************************/  



DECLARE @HTML  VARCHAR(MAX),

    @table VARCHAR(MAX)



 SET @HTML = --HTML layout--

            '&lt;html&gt;&lt;head&gt;' +

            '&lt;H1 style="color: #000000"&gt;Error Executing GetAllJobStatuses&lt;/H1&gt;' +

            '&lt;style&gt;' +

            'td {border: solid black 1px;padding-left:5px;padding-right:5px;padding-top:1px;padding-bottom:1px;font-size:9pt;color:Black;} ' +

            '&lt;/style&gt;' +

            '&lt;/head&gt;' +

            '&lt;body&gt;&lt;table cellpadding=0 cellspacing=0 border=0&gt;' +

            '&lt;tr bgcolor=33ffff&gt;'+  

            '&lt;td align=center&gt;Server Name&lt;/b&gt;&lt;/td&gt;' + 

            '&lt;td align=center&gt;Error Number&lt;/b&gt;&lt;/td&gt;' + 

            '&lt;td align=center&gt;Error Severity&lt;/b&gt;&lt;/td&gt;' + 

            '&lt;td align=center&gt;Error State&lt;/b&gt;&lt;/td&gt;' + 

            '&lt;td alignISNULL(=center&gt;Error Procedure&lt;/b&gt;&lt;/td&gt;' +  

            '&lt;td align=center&gt;Error Message&lt;/b&gt;&lt;/td&gt;&lt;/tr&gt;';                                



 SELECT @table = CONVERT(nvarchar(max) ,

(SELECT

 td = ServerName, '', 

 td = CAST(ErrorNumber as varchar(30)), '',  

 td = CAST(ErrorSeverity as varchar(30)), '', 

 td = CAST(ErrorState as varchar(30)), '', 

 td = ISNULL(CONVERT(VARCHAR(50),[ErrorProcedure] ),''), '',  

 td = ErrorMessage, ''                                    

 FROM                                   

#ERROR

FOR XML PATH(N'tr'), TYPE));



SET @HTML = @HTML + @table + CHAR(10) + 

         N'&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;';

SET @HTML = @HTML + '&lt;TR&gt;&lt;/TR&gt;&lt;B&gt;End of Report&lt;/B&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;';

--PRINT @HTML



Declare @MailSubject varchar(100)

SET @MailSubject = 'Error Executing GetAllJobStatuses!! - ' + 
DATENAME(weekday, getdate())

IF LEN(@HTML) &gt; 10      



EXEC msdb.dbo.sp_send_dbmail

@recipients = 'tester@test.com',

@body_format =  'HTML',

@body= @HTML,

@subject = @MailSubject,

@profile_name = 'SQLDBA'

    --SELECT * FROM #ERROR



 DROP TABLE #ERROR 

 END CATCH;