fixed AttributeError with try/except