If you want to log detailed information on an error in a catch block, you can use the following code:

 

BEGIN CATCH
        declare @Message varchar(2048) = 
        '<< Your custom error text here. >>' + 
        'Number: ' + cast(isnull(error_number(), '') as varchar(50)) + ' ' +
        'Severity: ' + cast(isnull(error_severity(), '') as varchar(50)) + ' ' +
        'State: ' + cast(isnull(error_state(), '') as varchar(100)) + ' ' +
        'Procedure: ' + cast(isnull(error_procedure(), '') as varchar(1024)) + ' ' +
        'Line: ' + cast(isnull(error_line(), '') as varchar(10)) + ' ' +
        'Message: ' + cast(isnull(error_message(), '') as varchar(1024)) + ' '

        ROLLBACK TRANSACTION    

        RAISERROR (@Message, 16, 1)
        

 

END CATCH

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.