<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def execute_and_handle_webelement_exceptions(self, function_to_execute, name_of_action):
 """ Private method to be called by other methods to handle common WebDriverExceptions or throw a custom exception @type function_to_execute: types.FunctionType @param function_to_execute: A function containing some webdriver calls @type name_of_action: str @param name_of_action: The name of the action you are trying to perform for building the error message """

        if self.element is not None:
            attempts = 0
            while attempts < self.driver_wrapper.find_attempts+1:
                try:
                    attempts = attempts + 1
                    val = function_to_execute()
                    for cb in self.driver_wrapper.action_callbacks:
                        cb.__call__(self.driver_wrapper)
                    return val
                except StaleElementReferenceException:
                    self.element = self.driver_wrapper.find(self.locator, search_object=self.search_object).element
                except ElementNotVisibleException:
                    raise WebElementNotVisibleException.WebElementNotVisibleException(self,
                        'WebElement with locator: {} was not visible, so could not {}'.format(
                            self.locator, name_of_action))
                except MoveTargetOutOfBoundsException:
                    raise WebElementNotVisibleException.WebElementNotVisibleException(self,
                        'WebElement with locator: {} was out of window, so could not {}'.format(
                            self.locator, name_of_action))
                except TimeoutException:
                    raise WebDriverTimeoutException.WebDriverTimeoutException(
                        self.driver_wrapper, timeout=self.driver_wrapper.timeout, locator=self.locator,
                        msg='Timeout on action: {}'.format(name_of_action))
                except UnexpectedAlertPresentException:
                    msg = 'failed to parse message from alert'
                    try:
                        a = self.driver.switch_to_alert()
                        msg = a.text
                    finally:
                        raise UnexpectedAlertPresentException('Unexpected alert on page: {}'.format(msg))
                except BadStatusLine, e:
                    logging.getLogger(__name__).error('{} error raised on action: {} (line: {}, args:{}, message: {})'.format(
                        BadStatusLine.__class__.__name__,
                        name_of_action,
                        e.line,
                        e.args,
                        e.message
                    ))
                    raise

            raise StaleWebElementException.StaleWebElementException(self,
                'Cannot {} element with locator: {}; the reference to the WebElement was stale ({} attempts)'
                .format(name_of_action, self.locator, self.driver_wrapper.find_attempts))
        else:
            raise WebElementDoesNotExist.WebElementDoesNotExist(self,
                'Cannot {} element with locator: {}; it does not exist'.format(name_of_action, self.locator))