BEGIN TRY
BEGIN TRANSACTION
COMMIT
END TRY
BEGIN CATCH
-- Whoops, there was an error
IF @@TRANCOUNT > 0
ROLLBACK
-- Raise an error with the details of the exception
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
SELECT @ErrMsg = ERROR_MESSAGE(),
@ErrSeverity = ERROR_SEVERITY(),
@p_io_Is_Error = @@error
RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH