Skip to content

Instantly share code, notes, and snippets.

@SeriousM
Created August 13, 2014 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeriousM/027bff66984d1c53cd2f to your computer and use it in GitHub Desktop.
Save SeriousM/027bff66984d1c53cd2f to your computer and use it in GitHub Desktop.
TSQL Rethrow Exception
BEGIN TRY
...
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION;
THROW;
END CATCH
BEGIN TRY
...
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION;
DECLARE @ErrorMessage nvarchar(4000) = ERROR_MESSAGE(),
@ErrorNumber int = ERROR_NUMBER(),
@ErrorSeverity int = ERROR_SEVERITY(),
@ErrorState int = ERROR_STATE(),
@ErrorLine int = ERROR_LINE(),
@ErrorProcedure nvarchar(200) = ISNULL(ERROR_PROCEDURE(), '-');
SELECT @ErrorMessage = N'Error %d, Level %d, State %d, Procedure %s, Line %d, ' + 'Message: ' + @ErrorMessage;
RAISERROR (@ErrorMessage, @ErrorSeverity, 1, @ErrorNumber, @ErrorSeverity, @ErrorState, @ErrorProcedure, @ErrorLine);
END CATCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment