1

This is what I've tried, but I am getting Error: Unknown exception thrown

try{//load std::ifstream stream(arch_name.c_str()); std::cout << ">> " << "Started deserializing " << arch_name << std::endl; boost::archive::binary_iarchive arc(stream); arc & c & matrix; stream.close(); std::cout << ">> " << "Finished deserializing" << std::endl; }catch(std::exception e){ std::cout << "Error: " << e.what() << std::endl; return 1; } 

This is working well in Linux with gcc. I am using Visual Studio in windows.

Edit

backtrace is showing that basic_binary_iprimitive.hpp is throwing exception on

template<class Archive, class Elem, class Tr> inline void basic_binary_iprimitive<Archive, Elem, Tr>::load_binary( void *address, std::size_t count){ //..... if(scount != s) boost::serialization::throw_exception( archive_exception(archive_exception::input_stream_error) ); 

Edit

I changed the catch black to catch(boost::archive::archive_exception e) and it printed. input stream error

Is there any miss in virtual what in boost archive exception ?

12
  • Can you tell which statement throws the exception? Commented Aug 12, 2012 at 17:14
  • 1
    Where is the exception thrown? Enable first-chance exception handling (Debug -> Exceptions, check the C++ Exceptions box). Commented Aug 12, 2012 at 17:14
  • Was the binary archive written under Windows? Commented Aug 12, 2012 at 17:15
  • Yes Thats the option I was looking here and there. I am first time on VisualStudio Commented Aug 12, 2012 at 17:16
  • 4
    You miss std::ios::binary. It seems to be required on Windows (otherwise EOL characters are corrupted). Commented Aug 12, 2012 at 17:32

1 Answer 1

6

I ran across this question because I had the same problem - a boost serialisation exception on Windows. I found the solution in Greg's comments: define the i/o mode when creating the data stream.

I changed this:

std::ofstream ofs(filename); boost::archive::binary_oarchive ar(ofs); 

To this:

std::ofstream ofs(filename, std::ios::binary); boost::archive::binary_oarchive ar(ofs); 

And then no more exceptions occurred when deserialising!

I thought this question needed an actual answer (not just a comment), so I'm adding it myself, but all credit goes to Greg.

Sign up to request clarification or add additional context in comments.

1 Comment

This solved my issue after two days of trying. THANK YOU!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.