Error handling, Close writer properly.