<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def transfer(cls, field_mappings, source, destination_factory):
 """Convert a record to a dictionary via field_mappings, and pass that to destination_factory."""

    data = dict()
    for index, field_mapping in enumerate(field_mappings):
      try:
        data[field_mapping.destination_name] = field_mapping.get_value(source)
      except Exception as ex:
        raise Exception(
          "Error with mapping #{0} '{1}'->'{2}': {3}".format(
            index,
            field_mapping.source_name,
            field_mapping.destination_name, ex)) from ex
    return destination_factory(data)