1 /* Copyright (C) 2015 The libxml++ development team
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <libxml++/libxml++.h>
26 class MySaxParser : public xmlpp::SaxParser
29 void on_start_document() override
31 throw std::runtime_error("some custom runtime exception");
33 void on_error(const Glib::ustring& /* text */) override
35 throw std::runtime_error("on_error() called");
46 bool exceptionThrown = false;
49 parser.parse_chunk("<?");
50 parser.finish_chunk_parsing();
52 #ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
53 catch(const std::runtime_error& e)
55 catch(const xmlpp::exception& e)
58 exceptionThrown = true;
59 g_assert_cmpstr(e.what(), ==, "on_error() called");
61 g_assert_true(exceptionThrown);
63 // Try parsing a stream now.
64 exceptionThrown = false;
67 std::stringstream ss("<root></root>");
68 parser.parse_stream(ss);
70 catch(const xmlpp::parse_error& e)
72 // An "Attempt to start a second parse while a parse is in progress." parse
73 // error should not have been thrown.
74 g_assert_not_reached();
76 #ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
77 catch(const std::runtime_error& e)
79 catch(const xmlpp::exception& e)
82 exceptionThrown = true;
83 g_assert_cmpstr(e.what(), ==, "some custom runtime exception");
85 g_assert_true(exceptionThrown);