* included with libxml++ as the file COPYING.
*/
+#include "libxml++/exceptions/wrapped_exception.h"
#include "libxml++/parsers/parser.h"
#include <libxml/parser.h>
};
Parser::Parser()
-: context_(nullptr), exception_ptr_(nullptr), pimpl_(new Impl)
+: context_(nullptr), exception_(nullptr), pimpl_(new Impl)
{
}
void Parser::check_for_error_and_warning_messages()
{
- Glib::ustring msg;
- try
- {
- if (exception_ptr_)
- std::rethrow_exception(exception_ptr_);
- }
- catch (const std::exception& e)
- {
- msg = e.what();
- }
- catch (...)
- {
- msg = "Unknown exception\n";
- }
+ Glib::ustring msg(exception_ ? exception_->what() : "");
bool parser_msg = false;
bool validity_msg = false;
pimpl_->validate_warning_.erase();
}
- try
- {
- if (validity_msg)
- throw validity_error(msg);
- else if (parser_msg)
- throw parse_error(msg);
- }
- catch (...)
- {
- exception_ptr_ = std::current_exception();
- }
+ if (validity_msg)
+ exception_.reset(new validity_error(msg));
+ else if (parser_msg)
+ exception_.reset(new parse_error(msg));
}
//static
// returns an error message (as it usually does).
//Convert the ... to a string:
- char buff[1024];
-
- vsnprintf(buff, sizeof(buff)/sizeof(buff[0]), msg, var_args);
- ubuff = buff;
+ ubuff = format_printf_message(msg, var_args);
}
try
void Parser::handle_exception()
{
- exception_ptr_ = std::current_exception();
+ try
+ {
+ throw; // Re-throw current exception
+ }
+ catch (const exception& e)
+ {
+ exception_.reset(e.clone());
+ }
+#ifdef LIBXMLXX_HAVE_EXCEPTION_PTR
+ catch (...)
+ {
+ exception_.reset(new wrapped_exception(std::current_exception()));
+ }
+#else
+ catch (const std::exception& e)
+ {
+ exception_.reset(new exception(e.what()));
+ }
+ catch (...)
+ {
+ exception_.reset(new exception("An exception was thrown that is not derived from std::exception or xmlpp::exception.\n"
+ "It could not be caught and rethrown because this platform does not support std::exception_ptr."));
+ }
+#endif
if (context_)
xmlStopParser(context_);
{
check_for_error_and_warning_messages();
- if (exception_ptr_)
+ if (exception_)
{
- std::exception_ptr tmp(exception_ptr_);
- exception_ptr_ = nullptr;
- std::rethrow_exception(tmp);
+ std::unique_ptr<exception> tmp(std::move(exception_));
+ tmp->raise();
}
}