Ensured exception handling for countCharOccur