简体   繁体   中英

File corruption in de-serialization, how to prevent a crash?

I'am using boost graph library to work with graphs. I use boost::serialization to write my graph to a file.

For testing purpose, I modifed the integrity of the file. Now my program just crashed all the time. I was wondering is there any way to prevent the crash (boost::serialization doesn't throw exceptions).

And more generally for any type of file with no exception thrown in parsing, where all is supposed to be correct, is there a way too ?

Maybe the only solution is to write custom serialization/de-serialization functions with exception handling ?

Thank you !

Edit: There is a boost::archive::archive_exception when the all data is corrupted or the file is missing. But if only certain part of the file are changed, it crashes ...

Edit2: I should caught the input_stream_error exception, but I don't.

A boost::archive_exception is also thrown in other situations than corruption of the whole data or missing file. See Archive Exceptions for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM