Fixing misplaced do{}while and try{}catch(){}