fix throwing of errors and test of throwing of errors