Replace incorrectly used asserts by exceptions

Change-Id: I52a5853eb86be4e6a10e3ec2d3b10915e00e0597