outputs errors to txt file, end loop when error given