Fix: Properly test and handle exceptions inMainLoop.