Introduce IllegalValueException

Change-Id: Ib7d85555748630a367b1f79a17ab02490d00ba26
Fix exception checking in test cases

Also fixes some broken tests.

Change-Id: I1bb11e7bc7676caba3f9bee6c335df492933a71b