Skip to content

Instantly share code, notes, and snippets.

@tompazourek
Last active August 29, 2015 14:27
Show Gist options
  • Save tompazourek/8d650ee6dadfb5fbc780 to your computer and use it in GitHub Desktop.
Save tompazourek/8d650ee6dadfb5fbc780 to your computer and use it in GitHub Desktop.
BEGIN TRY
BEGIN TRANSACTION
-- statements here
COMMIT TRAN
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK TRAN
PRINT 'Actual error number: ' + CAST(ERROR_NUMBER() AS VARCHAR(10));
PRINT 'Actual line number: ' + CAST(ERROR_LINE() AS VARCHAR(10));
DECLARE @ErrorMessage NVARCHAR(4000) = ERROR_MESSAGE();
DECLARE @ErrorSeverity INT = ERROR_SEVERITY();
DECLARE @ErrorState INT = ERROR_STATE();
RAISERROR(@ErrorMessage, @ErrorSeverity, @ErrorState);
END CATCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment