surround main loop with try catch