Replacing assertion by exceptions