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;
|
||||
return 1;
|
||||
}
|
||||
catch (const std::runtime_error& err) {
|
||||
std::cerr << err.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "xpath.hpp"
|
||||
#include <xercesc/framework/MemBufInputSource.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xqilla/exceptions/XQException.hpp>
|
||||
#include <xqilla/exceptions/XMLParseException.hpp>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
|
@ -54,18 +55,13 @@ namespace duck {
|
|||
auto XPath::run_query (const std::string& parXML, const std::vector<std::string>& parQueries) -> BatchResults {
|
||||
XQilla& xqilla = m_xqilla;
|
||||
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);
|
||||
Node::Ptr ptr;
|
||||
BatchResults retval;
|
||||
try {
|
||||
ptr = context->parseDocument(input_buf);
|
||||
}
|
||||
catch (const XMLParseException& err) {
|
||||
throw ParseError(err.getXQueryLine(), err.getXQueryColumn(), xercesc::XMLString::transcode(err.getError()));
|
||||
}
|
||||
AutoDelete<DynamicContext> context(xqilla.createContext(XQilla::XQUERY_UPDATE, &xconfig));
|
||||
Node::Ptr ptr = context->parseDocument(input_buf);
|
||||
context->setContextItem(ptr);
|
||||
|
||||
BatchResults retval;
|
||||
for (const auto& xpath : parQueries) {
|
||||
AutoDelete<XQQuery> query(xqilla.parse(X(xpath.c_str())));
|
||||
context->setContextPosition(1);
|
||||
|
@ -77,8 +73,17 @@ namespace duck {
|
|||
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) {
|
||||
throw ParseError(err.getXQueryLine(), err.getXQueryColumn(), xercesc::XMLString::transcode(err.getError()));
|
||||
}
|
||||
catch (const XQException& err) {
|
||||
throw std::runtime_error(xercesc::XMLString::transcode(err.getError()));
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue