|
Boost Users : |
From: gast128 (gast128_at_[hidden])
Date: 2007-03-02 05:00:25
Robert Ramey <ramey <at> rrsd.com> writes:
> Note: the function of 'delete_created_pointers' is to delete any
> pointer created during the process of loading. Construction
> of an archive creates no such pointers. So not calling
> 'delete_created_pointers' in this case will have no effect and
> does not need to be called.
Ok 3 things:
1) I think a throwing ctor should not create memory leaks. I believe Sutter
has comments about this in his book
2) The loaded XML file can be altered by users. Therfore the load can fail and
I want it to be guarded. But now I have to add a double guard:
bool Load(const std::string& cr)
{
std::fstream fstr(cr);
try
{
boost::archive::xml_iarchive ia(fstr);
try
{
ia >> ...;
return true;
}
catch (boost::archive::archive_exception& re)
{
ia.delete_created_pointers();
}
}
catch (boost::archive::archive_exception& re)
{
}
return false;
}
3) I am aware of this 'exception versus error returning' discussions. A good
article is written by Sutter in cuj august 2004 'When and How to Use
Exceptions'. But I get the impression that this is a discussion between
academic correct code versus common practice. In our company we have the
policy that subsystems should not let escape exceptions. An unimportant class
should not terminate the application because an exception is not caught. The
GUI layer should not terminate the application because it cannot display all
its elements. I would suggest for those c++ gurus to take software
architecture in consideration when requiring this exception stuff for all
classes. If you follow their rules all the time it takes twice the effort to
code applications. And it will probably terminate a lot more due to uncaught
exceptions from the 80% classes which are mildly important.
Wkr,
me
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net