using hasattr instead of exception handling