Added exception handling for switch