handle the exception in the loop outside of the class.