Throw IOExceptions on bogus input.

Previously we were throwing various unchecked exceptions and this was
causing services to be unhappy.