Skip to content

Return None instead of raising Exception #76

@3ev0

Description

@3ev0

Hi,

When requesting a (sub)key, Registry raises an exception if this key is not found. The same for values. Since actually the easiest way to check if a key exists (implicitly) to call key.subkey() and then the absence of the subkey is not really an exception in that sense.
Would you consider replacing the exception-raising with returning None? or maybe add functions with that return None instead of raise exception.

Like this:

 def subkey(self, name):
        """
        Return the subkey with a given name as a RegistryKey.
        Return None if the subkey with the given name does not exist. 
        """
        if self._nkrecord.subkey_number() == 0:
            return None

        for k in self._nkrecord.subkey_list().keys():
            if k.name().lower() == name.lower():
                return RegistryKey(k)
        return None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions