Fix write verification before we attempt to read, or throw invalid errormessage

Discovered by Coverity