Your definition of "something goes wrong" is flawed.
In your definition, you only take into account problems while constructing the datastream.
However, writing the datastream to a file can go wrong too.
In other words, even if your datastream is completely correct, writing it to a file can result in a corrupt file when, for example, there's not enough disk space or when there are conflicts in who has access to the file etc...
Therefor, your suggestion to work with temporary files is the best way to check if the saved file is correct.
You could use a version control system too of course, like svn etc...
Bookmarks