<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def _get_user_dir(self):
        '''
        Get the user's home directory.
        '''
        try:
            # This should work in both Windows and Unix environments
            for envname in ['USERPROFILE', 'HOME']:
                user_dir = os.getenv(envname)
                if user_dir is not None:
                    return user_dir
        except KeyboardInterrupt as e:
            raise e
        except Exception:
            pass

        return ''