def parse_int(arg, name, parser):
    """
    Tries to parse a string as an integer.

    :param arg:    The arg to parse as an integer
    :param name:   A description of the argument used for error messages
    :param parser: The parser used to report an error message
    :return: The parsed integer if succeeds or None if fails
    """
    if arg:
        try:
            arg = int(arg)
            return arg
        except ValueError:
            parser.error("'" + arg + "' is not a valid " + name)
            return None
