Added exception handler to main functions so that the whole loop does not stop upon failure.