|
From: <vac...@us...> - 2010-02-17 16:15:17
|
Revision: 170
http://xmlwrapp.svn.sourceforge.net/xmlwrapp/?rev=170&view=rev
Author: vaclavslavik
Date: 2010-02-17 16:15:08 +0000 (Wed, 17 Feb 2010)
Log Message:
-----------
Added xml::exception class, derived from std::runtime_error.
This makes it possible to distinguish XML exceptions from other runtime
errors. xmlwrapp will throw only this or derived exception, with the
exception of std::bad_alloc(), which is still thrown when appropriate.
Modified Paths:
--------------
trunk/NEWS
trunk/include/Makefile.am
trunk/include/xmlwrapp/tree_parser.h
trunk/include/xmlwrapp/xmlwrapp.h
trunk/include/xsltwrapp/stylesheet.h
trunk/platform/Win32/xmlwrapp.bkl
trunk/src/libxml/ait_impl.cxx
trunk/src/libxml/document.cxx
trunk/src/libxml/node.cxx
trunk/src/libxml/node_manip.cxx
trunk/src/libxml/tree_parser.cxx
trunk/src/libxslt/stylesheet.cxx
Added Paths:
-----------
trunk/include/xmlwrapp/exception.h
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2010-02-17 16:12:14 UTC (rev 169)
+++ trunk/NEWS 2010-02-17 16:15:08 UTC (rev 170)
@@ -1,4 +1,8 @@
+ Added xml::exception class, derived from std::runtime_error. Xmlwrapp
+ will throw only this or derived exception, with the exception of
+ std::bad_alloc(), which is still thrown when appropriate.
+
Fixed compilation with Sun Studio compiler.
Version 0.6.2
Modified: trunk/include/Makefile.am
===================================================================
--- trunk/include/Makefile.am 2010-02-17 16:12:14 UTC (rev 169)
+++ trunk/include/Makefile.am 2010-02-17 16:15:08 UTC (rev 170)
@@ -5,6 +5,7 @@
xmlwrapp/_cbfo.h \
xmlwrapp/document.h \
xmlwrapp/event_parser.h \
+ xmlwrapp/exception.h \
xmlwrapp/init.h \
xmlwrapp/node.h \
xmlwrapp/nodes_view.h \
Copied: trunk/include/xmlwrapp/exception.h (from rev 169, trunk/include/xmlwrapp/xmlwrapp.h)
===================================================================
--- trunk/include/xmlwrapp/exception.h (rev 0)
+++ trunk/include/xmlwrapp/exception.h 2010-02-17 16:15:08 UTC (rev 170)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2010 Vaclav Slavik <vs...@fa...>
+ * All Rights Reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name of the Author nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/**
+ @file
+
+ This file contains the definition of the xml::exception class.
+ */
+
+#ifndef _xmlwrapp_exception_h_
+#define _xmlwrapp_exception_h_
+
+#include <stdexcept>
+#include <string>
+
+/// XML library namespace
+namespace xml
+{
+
+/**
+ This exception class is thrown by xmlwrapp for all runtime XML-related
+ errors.
+
+ @note C++ runtime may still thrown other errors when used from xmlwrapp.
+ Also, std::bad_alloc() is thrown in out-of-memory situations.
+
+ @since 0.7.0
+ */
+class exception : public std::runtime_error
+{
+public:
+ explicit exception(const std::string& what) : std::runtime_error(what)
+ {
+ }
+};
+
+} // namespace xml
+
+#endif // _xmlwrapp_exception_h_
Modified: trunk/include/xmlwrapp/tree_parser.h
===================================================================
--- trunk/include/xmlwrapp/tree_parser.h 2010-02-17 16:12:14 UTC (rev 169)
+++ trunk/include/xmlwrapp/tree_parser.h 2010-02-17 16:15:08 UTC (rev 170)
@@ -74,7 +74,7 @@
constructor will parse that file.
There are two options for dealing with XML parsing errors. The
- default it to throw an exception (std::runtime_error). The other
+ default it to throw an exception (xml::exception). The other
option is to pass false for the allow_exceptions flag. This will
prevent an exception from being thrown, instead, a flag will be set
that you can test with the operator! member function.
Modified: trunk/include/xmlwrapp/xmlwrapp.h
===================================================================
--- trunk/include/xmlwrapp/xmlwrapp.h 2010-02-17 16:12:14 UTC (rev 169)
+++ trunk/include/xmlwrapp/xmlwrapp.h 2010-02-17 16:15:08 UTC (rev 170)
@@ -41,5 +41,6 @@
#include "xmlwrapp/document.h"
#include "xmlwrapp/tree_parser.h"
#include "xmlwrapp/event_parser.h"
+#include "xmlwrapp/exception.h"
#endif // _xmlwrapp_xmlwrapp_h_
Modified: trunk/include/xsltwrapp/stylesheet.h
===================================================================
--- trunk/include/xsltwrapp/stylesheet.h 2010-02-17 16:12:14 UTC (rev 169)
+++ trunk/include/xsltwrapp/stylesheet.h 2010-02-17 16:15:08 UTC (rev 170)
@@ -118,7 +118,7 @@
/**
Apply this stylesheet to the given XML document. The results document
is returned. If there is an error during transformation, this
- function will throw a std::runtime_error exception.
+ function will throw a xml::exception exception.
Each time you call this member function, the xml::document object
that was returned from the last call becomes invalid. That is, of
@@ -133,7 +133,7 @@
/**
Apply this stylesheet to the given XML document. The results document
is returned. If there is an error during transformation, this
- function will throw a std::runtime_error exception.
+ function will throw a xml::exception exception.
Each time you call this member function, the xml::document object
that was returned from the last call becomes invalid. That is, of
@@ -153,7 +153,7 @@
If you are using one of the apply member functions that throws
exceptions, this function should not be used. The text message for
- the transformation error will be given to the std::runtime_error
+ the transformation error will be given to the xml::exception
constructor.
@return The last error message.
Modified: trunk/platform/Win32/xmlwrapp.bkl
===================================================================
--- trunk/platform/Win32/xmlwrapp.bkl 2010-02-17 16:12:14 UTC (rev 169)
+++ trunk/platform/Win32/xmlwrapp.bkl 2010-02-17 16:15:08 UTC (rev 170)
@@ -16,6 +16,7 @@
include/xmlwrapp/_cbfo.h
include/xmlwrapp/document.h
include/xmlwrapp/event_parser.h
+ include/xmlwrapp/exception.h
include/xmlwrapp/init.h
include/xmlwrapp/node.h
include/xmlwrapp/nodes_view.h
Modified: trunk/src/libxml/ait_impl.cxx
===================================================================
--- trunk/src/libxml/ait_impl.cxx 2010-02-17 16:12:14 UTC (rev 169)
+++ trunk/src/libxml/ait_impl.cxx 2010-02-17 16:15:08 UTC (rev 170)
@@ -34,10 +34,10 @@
#include "ait_impl.h"
#include "utility.h"
#include "xmlwrapp/attributes.h"
+#include "xmlwrapp/exception.h"
// standard includes
#include <algorithm>
-#include <stdexcept>
// libxml2 includes
#include <libxml/tree.h>
@@ -354,7 +354,7 @@
return name_.c_str(); // we were given a name not a node
if (!node_ || !prop_)
- throw std::runtime_error("access to invalid attributes::attr object!");
+ throw xml::exception("access to invalid attributes::attr object!");
return reinterpret_cast<const char*>(static_cast<xmlAttrPtr>(prop_)->name);
}
@@ -366,7 +366,7 @@
return value_.c_str(); // we were given a value, not a node
if (!node_ || !prop_)
- throw std::runtime_error("access to invalid attributes::attr object!");
+ throw xml::exception("access to invalid attributes::attr object!");
xmlChar *tmpstr = xmlNodeListGetString(reinterpret_cast<xmlNodePtr>(node_)->doc, reinterpret_cast<xmlAttrPtr>(prop_)->children, 1);
if (tmpstr == 0)
Modified: trunk/src/libxml/document.cxx
===================================================================
--- trunk/src/libxml/document.cxx 2010-02-17 16:12:14 UTC (rev 169)
+++ trunk/src/libxml/document.cxx 2010-02-17 16:15:08 UTC (rev 170)
@@ -33,6 +33,8 @@
// xmlwrapp includes
#include "xmlwrapp/document.h"
#include "xmlwrapp/node.h"
+#include "xmlwrapp/exception.h"
+
#include "utility.h"
#include "dtd_impl.h"
#include "node_manip.h"
@@ -367,7 +369,7 @@
void document::push_back(const node& child)
{
if (child.get_type() == node::type_element)
- throw std::runtime_error("xml::document::push_back can't take element type nodes");
+ throw xml::exception("xml::document::push_back can't take element type nodes");
impl::node_insert
(
@@ -381,7 +383,7 @@
node::iterator document::insert(const node& n)
{
if (n.get_type() == node::type_element)
- throw std::runtime_error("xml::document::insert can't take element type nodes");
+ throw xml::exception("xml::document::insert can't take element type nodes");
return node::iterator(xml::impl::node_insert(reinterpret_cast<xmlNodePtr>(pimpl_->doc_), 0, static_cast<xmlNodePtr>(const_cast<node&>(n).get_node_data())));
}
@@ -390,7 +392,7 @@
node::iterator document::insert(node::iterator position, const node& n)
{
if (n.get_type() == node::type_element)
- throw std::runtime_error("xml::document::insert can't take element type nodes");
+ throw xml::exception("xml::document::insert can't take element type nodes");
return node::iterator(xml::impl::node_insert(reinterpret_cast<xmlNodePtr>(pimpl_->doc_), static_cast<xmlNodePtr>(position.get_raw_node()), static_cast<xmlNodePtr>(const_cast<node&>(n).get_node_data())));
}
@@ -400,7 +402,7 @@
{
if (old_node->get_type() == node::type_element || new_node.get_type() == node::type_element)
{
- throw std::runtime_error("xml::document::replace can't replace element type nodes");
+ throw xml::exception("xml::document::replace can't replace element type nodes");
}
return node::iterator(xml::impl::node_replace(static_cast<xmlNodePtr>(old_node.get_raw_node()), static_cast<xmlNodePtr>(const_cast<node&>(new_node).get_node_data())));
@@ -410,7 +412,7 @@
node::iterator document::erase(node::iterator to_erase)
{
if (to_erase->get_type() == node::type_element)
- throw std::runtime_error("xml::document::erase can't erase element type nodes");
+ throw xml::exception("xml::document::erase can't erase element type nodes");
return node::iterator(xml::impl::node_erase(static_cast<xmlNodePtr>(to_erase.get_raw_node())));
}
Modified: trunk/src/libxml/node.cxx
===================================================================
--- trunk/src/libxml/node.cxx 2010-02-17 16:12:14 UTC (rev 169)
+++ trunk/src/libxml/node.cxx 2010-02-17 16:15:08 UTC (rev 170)
@@ -35,6 +35,7 @@
#include "xmlwrapp/node.h"
#include "xmlwrapp/nodes_view.h"
#include "xmlwrapp/attributes.h"
+#include "xmlwrapp/exception.h"
#include "utility.h"
#include "ait_impl.h"
#include "node_manip.h"
@@ -477,7 +478,7 @@
{
if (pimpl_->xmlnode_->type != XML_ELEMENT_NODE)
{
- throw std::runtime_error("get_attributes called on non-element node");
+ throw xml::exception("get_attributes called on non-element node");
}
pimpl_->attrs_.set_data(pimpl_->xmlnode_);
@@ -489,7 +490,7 @@
{
if (pimpl_->xmlnode_->type != XML_ELEMENT_NODE)
{
- throw std::runtime_error("get_attributes called on non-element node");
+ throw xml::exception("get_attributes called on non-element node");
}
pimpl_->attrs_.set_data(pimpl_->xmlnode_);
Modified: trunk/src/libxml/node_manip.cxx
===================================================================
--- trunk/src/libxml/node_manip.cxx 2010-02-17 16:12:14 UTC (rev 169)
+++ trunk/src/libxml/node_manip.cxx 2010-02-17 16:15:08 UTC (rev 170)
@@ -31,6 +31,8 @@
*/
// xmlwrapp includes
+#include "xmlwrapp/exception.h"
+
#include "node_manip.h"
// standard includes
@@ -53,7 +55,7 @@
if ( xmlAddChild(parent, new_xml_node) == 0 )
{
xmlFreeNode(new_xml_node);
- throw std::runtime_error("failed to insert xml::node; xmlAddChild failed");
+ throw xml::exception("failed to insert xml::node; xmlAddChild failed");
}
}
else
@@ -61,7 +63,7 @@
if ( xmlAddPrevSibling(before, new_xml_node) == 0 )
{
xmlFreeNode(new_xml_node);
- throw std::runtime_error("failed to insert xml::node; xmlAddPrevSibling failed");
+ throw xml::exception("failed to insert xml::node; xmlAddPrevSibling failed");
}
}
@@ -83,7 +85,7 @@
if ( copied_node->doc == reinterpret_cast<xmlDocPtr>(old_node) )
{
xmlFreeNode(copied_node);
- throw std::runtime_error("failed to replace xml::node; xmlReplaceNode() failed");
+ throw xml::exception("failed to replace xml::node; xmlReplaceNode() failed");
}
xmlFreeNode(old_node);
Modified: trunk/src/libxml/tree_parser.cxx
===================================================================
--- trunk/src/libxml/tree_parser.cxx 2010-02-17 16:12:14 UTC (rev 169)
+++ trunk/src/libxml/tree_parser.cxx 2010-02-17 16:15:08 UTC (rev 170)
@@ -33,6 +33,7 @@
// xmlwrapp includes
#include "xmlwrapp/tree_parser.h"
#include "xmlwrapp/document.h"
+#include "xmlwrapp/exception.h"
#include "utility.h"
// libxml includes
@@ -160,7 +161,7 @@
xmlFreeDoc(tmpdoc);
if (allow_exceptions)
- throw std::runtime_error(pimpl_->last_error_);
+ throw xml::exception(pimpl_->last_error_);
}
ap.release();
@@ -194,7 +195,7 @@
pimpl_->okay_ = false;
if (allow_exceptions)
- throw std::runtime_error(pimpl_->last_error_);
+ throw xml::exception(pimpl_->last_error_);
ap.release();
return; // handle non-exception case
Modified: trunk/src/libxslt/stylesheet.cxx
===================================================================
--- trunk/src/libxslt/stylesheet.cxx 2010-02-17 16:12:14 UTC (rev 169)
+++ trunk/src/libxslt/stylesheet.cxx 2010-02-17 16:15:08 UTC (rev 170)
@@ -40,6 +40,7 @@
#include "xsltwrapp/stylesheet.h"
#include "xmlwrapp/document.h"
#include "xmlwrapp/tree_parser.h"
+#include "xmlwrapp/exception.h"
#include "result.h"
#include "../libxml/utility.h"
@@ -51,7 +52,6 @@
#include <libxslt/xsltutils.h>
// standard includes
-#include <stdexcept>
#include <memory>
#include <string>
#include <vector>
@@ -207,7 +207,7 @@
// TODO error_ can't get set yet. Need changes from libxslt first
if (pimpl_->error_.empty())
pimpl_->error_ = "unknown XSLT parser error";
- throw std::runtime_error(pimpl_->error_);
+ throw xml::exception(pimpl_->error_);
}
// if we got this far, the xmldoc we gave to xsltParseStylesheetDoc is
@@ -227,7 +227,7 @@
// TODO error_ can't get set yet. Need changes from libxslt first
if (pimpl_->error_.empty())
pimpl_->error_ = "unknown XSLT parser error";
- throw std::runtime_error(pimpl_->error_);
+ throw xml::exception(pimpl_->error_);
}
// if we got this far, the xmldoc we gave to xsltParseStylesheetDoc is
@@ -282,7 +282,7 @@
xmlDocPtr xmldoc = apply_stylesheet(pimpl_, input);
if ( !xmldoc )
- throw std::runtime_error(pimpl_->error_);
+ throw xml::exception(pimpl_->error_);
pimpl_->doc_.set_doc_data_from_xslt(xmldoc, new result_impl(xmldoc, pimpl_->ss_));
return pimpl_->doc_;
@@ -296,7 +296,7 @@
xmlDocPtr xmldoc = apply_stylesheet(pimpl_, input, &with_params);
if ( !xmldoc )
- throw std::runtime_error(pimpl_->error_);
+ throw xml::exception(pimpl_->error_);
pimpl_->doc_.set_doc_data_from_xslt(xmldoc, new result_impl(xmldoc, pimpl_->ss_));
return pimpl_->doc_;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|