Throw exceptions when value is invalid

Change-Id: Id08f385c08260afa69ba09da236d731a5dca3ac6