级联Poco异常

时间:2014-08-29 09:00:17

标签: c++ exception poco-libraries

我尝试在Poco中级联异常。

void debug() {
try {
    ...
    xmlFile.parseDocument(*_sim);
    ...
    }
} catch (Poco::Exception& error) {
    std::cout << "I'm here" << endl;
    std::cout << "Error : " << error.displayText() << std::endl;
}
}

void XMLParser::parseDocument(Manager &manager) {
...
try {
    Poco::XML::NodeList* policyList = root->childNodes();
    for (uint node=0; node < policyList->length(); node++)
        if (policyList->item(node)->hasChildNodes())
            manager.insertRule(parseRule(node, policyList->item(node)));
} catch(Poco::Exception& error) {
    std::cout << "Error : " << error.displayText() << std::endl;
    error.rethrow();
}
}

Rule* XMLParser::parseRule(int flowID, Poco::XML::Node* rule) throw() {
    ....
    if (tLink._srcPort < 0)
        throw new Poco::Exception("Source Port isn't valid");
    ....
}

抛出最深的异常,但它不会继续外部函数。 该计划终止。为什么呢?

1 个答案:

答案 0 :(得分:2)

您抛出一个Poco :: Exception指针,因此您无法通过引用捕获它。 删除&#39; new&#39;。这应该有效:

....
if (tLink._srcPort < 0)
    throw Poco::Exception("Source Port isn't valid");
....