Fix some exceptions crashing the program
This commit is contained in:
parent
7170347969
commit
d97cf03a34
2 changed files with 27 additions and 18 deletions
|
@ -62,6 +62,10 @@ int main (int argc, char* argv[]) {
|
||||||
std::cerr << err.what() << std::endl;
|
std::cerr << err.what() << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
catch (const std::runtime_error& err) {
|
||||||
|
std::cerr << err.what() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "xpath.hpp"
|
#include "xpath.hpp"
|
||||||
#include <xercesc/framework/MemBufInputSource.hpp>
|
#include <xercesc/framework/MemBufInputSource.hpp>
|
||||||
#include <xercesc/util/XMLString.hpp>
|
#include <xercesc/util/XMLString.hpp>
|
||||||
|
#include <xqilla/exceptions/XQException.hpp>
|
||||||
#include <xqilla/exceptions/XMLParseException.hpp>
|
#include <xqilla/exceptions/XMLParseException.hpp>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
@ -54,31 +55,35 @@ namespace duck {
|
||||||
auto XPath::run_query (const std::string& parXML, const std::vector<std::string>& parQueries) -> BatchResults {
|
auto XPath::run_query (const std::string& parXML, const std::vector<std::string>& parQueries) -> BatchResults {
|
||||||
XQilla& xqilla = m_xqilla;
|
XQilla& xqilla = m_xqilla;
|
||||||
XercesConfiguration xconfig;
|
XercesConfiguration xconfig;
|
||||||
AutoDelete<DynamicContext> context(xqilla.createContext(XQilla::XQUERY_UPDATE, &xconfig));
|
|
||||||
xercesc::MemBufInputSource input_buf(reinterpret_cast<const XMLByte*>(parXML.c_str()), parXML.size(), "n/a", false);
|
xercesc::MemBufInputSource input_buf(reinterpret_cast<const XMLByte*>(parXML.c_str()), parXML.size(), "n/a", false);
|
||||||
Node::Ptr ptr;
|
BatchResults retval;
|
||||||
try {
|
try {
|
||||||
ptr = context->parseDocument(input_buf);
|
AutoDelete<DynamicContext> context(xqilla.createContext(XQilla::XQUERY_UPDATE, &xconfig));
|
||||||
|
Node::Ptr ptr = context->parseDocument(input_buf);
|
||||||
|
context->setContextItem(ptr);
|
||||||
|
|
||||||
|
for (const auto& xpath : parQueries) {
|
||||||
|
AutoDelete<XQQuery> query(xqilla.parse(X(xpath.c_str())));
|
||||||
|
context->setContextPosition(1);
|
||||||
|
context->setContextSize(1);
|
||||||
|
|
||||||
|
Result result = query->execute(context);
|
||||||
|
Item::Ptr item;
|
||||||
|
std::vector<std::pair<std::string, std::string>> new_lst;
|
||||||
|
while(nullptr != (item = result->next(context))) {
|
||||||
|
new_lst.push_back(std::make_pair(std::string(), UTF8(item->asString(context))));
|
||||||
|
}
|
||||||
|
|
||||||
|
retval.push_back(std::move(new_lst));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (const XMLParseException& err) {
|
catch (const XMLParseException& err) {
|
||||||
throw ParseError(err.getXQueryLine(), err.getXQueryColumn(), xercesc::XMLString::transcode(err.getError()));
|
throw ParseError(err.getXQueryLine(), err.getXQueryColumn(), xercesc::XMLString::transcode(err.getError()));
|
||||||
}
|
}
|
||||||
context->setContextItem(ptr);
|
catch (const XQException& err) {
|
||||||
|
throw std::runtime_error(xercesc::XMLString::transcode(err.getError()));
|
||||||
BatchResults retval;
|
|
||||||
for (const auto& xpath : parQueries) {
|
|
||||||
AutoDelete<XQQuery> query(xqilla.parse(X(xpath.c_str())));
|
|
||||||
context->setContextPosition(1);
|
|
||||||
context->setContextSize(1);
|
|
||||||
|
|
||||||
Result result = query->execute(context);
|
|
||||||
Item::Ptr item;
|
|
||||||
std::vector<std::pair<std::string, std::string>> new_lst;
|
|
||||||
while(nullptr != (item = result->next(context))) {
|
|
||||||
new_lst.push_back(std::make_pair(std::string(), UTF8(item->asString(context))));
|
|
||||||
}
|
|
||||||
retval.push_back(std::move(new_lst));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue