31 December, 2013
0 Comments
1 category
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
Tags: T-SQL
Category: Uncategorized