Add some error handling to tfilestream.cpp