From: Arvin Schnell Date: Fri, 7 Oct 2011 09:34:00 +0000 (+0200) Subject: - cleaner code X-Git-Tag: v0.1.3~272 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=183c3b027db2ecfd230115221b84587565eaf0d8;p=thirdparty%2Fsnapper.git - cleaner code --- diff --git a/snapper/Exception.h b/snapper/Exception.h index b885db76..0c628fa4 100644 --- a/snapper/Exception.h +++ b/snapper/Exception.h @@ -50,6 +50,12 @@ namespace snapper virtual const char* what() const throw() { return "illegal snapshot"; } }; + struct BadAllocException : public SnapperException + { + explicit BadAllocException() throw() {} + virtual const char* what() const throw() { return "bad alloc"; } + }; + struct LogicErrorException : public SnapperException { explicit LogicErrorException() throw() {} diff --git a/snapper/XmlFile.cc b/snapper/XmlFile.cc index 42499d8e..1ae64952 100644 --- a/snapper/XmlFile.cc +++ b/snapper/XmlFile.cc @@ -32,6 +32,8 @@ namespace snapper XmlFile::XmlFile() : doc(xmlNewDoc((const xmlChar*) "1.0")) { + if (!doc) + throw BadAllocException(); } @@ -45,8 +47,7 @@ namespace snapper XmlFile::~XmlFile() { - if (doc) - xmlFreeDoc(doc); + xmlFreeDoc(doc); }