Change assert to exception