i'm a beginner so i could be wrong but from the handle_error part of the code it seems there could be a risk of a possible loop upon failure to close files (output and input)