def pdu_to_function_code_or_raise_error(resp_pdu):
function_code = struct.unpack('<STR_LIT>', resp_pdu[<NUM_LIT:0>:<NUM_LIT:1>])[<NUM_LIT:0>]<EOL>if function_code not in function_code_to_function_map.keys():<EOL><INDENT>error_code = struct.unpack('<STR_LIT>', resp_pdu[<NUM_LIT:1>:<NUM_LIT:2>])[<NUM_LIT:0>]<EOL>raise error_code_to_exception_map[error_code]<EOL><DEDENT>return function_code<EOL>
Parse response PDU and return of :class:`ModbusFunction` or
    raise error.

    :param resp_pdu: PDU of response.
    :return: Subclass of :class:`ModbusFunction` matching the response.
    :raises ModbusError: When response contains error code.