Catch AttributeError exception in generate_exception