Throw exception instead of assert

Change-Id: Ia43842012e5d682cd448bf64791dd41dfca49963