This is a bug, you're throwing the exception before looping through the characters, if you take a look at the original code this check was done after the loop below.