def check_valid_varname(varname,
                        custom_units,
                        custom_structs,
                        constants,
                        pos,
                        error_prefix="Variable name invalid.",
                        exc=None):
    """ Handle invalid variable names """
    exc = VariableDeclarationException if exc is None else exc

    valid_varname, msg = is_varname_valid(varname, custom_units, custom_structs, constants)
    if not valid_varname:
        raise exc(error_prefix + msg, pos)

    return True