Fix exception handling in setupCommandLoop