Cleaned up exceptions.

The exceptions should now generally be the same for similar errors (but
different types). The locality of the exception was improved by moving the
throw to the failure site instead of going to a generic 'invalid' label.