Unserialize throws an exception
Dear all,
I'm trying to unserialize a boost::archive::text_iarchive. The code used to
work, but know (for no apparent reasons) it's calling terminate throwing
the following exception.
terminate called after throwing an instance of 'boost::archive::archive_exception
what(): stream error
Aborted
The piece of code is very simple:
std::ifstream ifs(filename);
boost::archive::text_iarchive ia(ifs);
ia >> map;
where map is an STL hash_multimap. Any ideas? Btw, this is one of the first
thing I'm doing in the code. Nonetheless to say, another code of mine which
serialize and unserialize works like a charm...
Boost library version is 1.34.1.
TIA, bye
Lorenzo
--
Lorenzo `Gigi Sullivan' Cavallaro
On Wed, 16 Jan 2008 13:09:17 -0500 Lorenzo Cavallaro wrote:
I'm trying to unserialize a boost::archive::text_iarchive. The code used to work, but know (for no apparent reasons) it's calling terminate throwing the following exception.
terminate called after throwing an instance of 'boost::archive::archive_exception what(): stream error Aborted
Hi Lorenzo, Under these circumstances: 1) classes contain float or double members 2a) [intentional] the floats/doubles are used to store NaN or +/-Inf values 2a) [unintentional] the floats or doubles are un-initialized and the memory they use just happens to contain (by circumstance) bit patterns for NaN or +/-Inf serialization to text or XML will "work" (that is, will run without errors) but de-serialization will result in stream errors since: double a; cin >> a; fails for "NaN", "Inf", etc. Ed -- Edward H. Hill III, PhD | ed@eh3.com | http://eh3.com/
Ed Hill wrote:
On Wed, 16 Jan 2008 13:09:17 -0500 Lorenzo Cavallaro wrote:
I'm trying to unserialize a boost::archive::text_iarchive. The code used to work, but know (for no apparent reasons) it's calling terminate throwing the following exception.
terminate called after throwing an instance of 'boost::archive::archive_exception what(): stream error Aborted
Hi Lorenzo,
Under these circumstances:
1) classes contain float or double members 2a) [intentional] the floats/doubles are used to store NaN or +/-Inf values 2b) [unintentional] the floats or doubles are un-initialized and the memory they use just happens to contain (by circumstance) bit patterns for NaN or +/-Inf
serialization to text or XML will "work" (that is, will run without errors) but de-serialization will result in stream errors since:
double a; cin >> a;
fails for "NaN", "Inf", etc.
Ed
If the problem is the presence of infinity and NaN, then you can solve the problem by using my Floating Point Utilities library. It is available in the vault in folder Math - Numerics. You need the facets in the header non_finite_num_facets.hpp. It is not accepted into Boost yet, but the code is mature and has been tested with more than 20 different operating system / compiler / processor combinations. --Johan Råde
On Wed, 16 Jan 2008 21:23:27 +0100 Johan Råde wrote:
If the problem is the presence of infinity and NaN, then you can solve the problem by using my Floating Point Utilities library. It is available in the vault in folder Math - Numerics. You need the facets in the header non_finite_num_facets.hpp.
I don't know if Lorenzo's problem was due to Infs/NaNs. I just wanted to suggest it as a possible explanation for text de-serialization stream errors.
It is not accepted into Boost yet, but the code is mature and has been tested with more than 20 different operating system / compiler / processor combinations.
Thank you for pointing that out! It looks quite useful. Ed -- Edward H. Hill III, PhD | ed@eh3.com | http://eh3.com/
Dear All, for some reason I still haven't received Ed msg thru boost-users mailing list, but, anyway, seeing it quoted helped out ;-) Basically, I had an old but working serialized model, M, but I made a change to the new code base (library) by adding one extra bool (which I didn't remember to as it was a very small change) to the serialized class. Thus, the new library code failed to unserialize M due to this inconsistency. A "fresh" model solved the issue (more or less; it's a little bit more complicated than this, but it'd be useless to bother you :-)). My bad ;-) Thanks! The hint helped a lot! bye, Lorenzo On Wed, Jan 16, 2008 at 09:23:27PM +0100, Johan R?de wrote:
Hi Lorenzo,
Under these circumstances:
1) classes contain float or double members 2a) [intentional] the floats/doubles are used to store NaN or +/-Inf values 2b) [unintentional] the floats or doubles are un-initialized and the memory they use just happens to contain (by circumstance) bit patterns for NaN or +/-Inf
serialization to text or XML will "work" (that is, will run without errors) but de-serialization will result in stream errors since:
double a; cin >> a;
fails for "NaN", "Inf", etc.
Ed
If the problem is the presence of infinity and NaN, then you can solve the problem by using my Floating Point Utilities library. It is available in the vault in folder Math - Numerics. You need the facets in the header non_finite_num_facets.hpp.
It is not accepted into Boost yet, but the code is mature and has been tested with more than 20 different operating system / compiler / processor combinations.
--Johan Råde
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
--
Lorenzo `Gigi Sullivan' Cavallaro
participants (3)
-
Ed Hill
-
Johan Råde
-
Lorenzo Cavallaro