fix CodeWriterTest and change exception