use try/except instead of hasattr