gpt4 book ai didi

c++ - 级联 Poco 异常

转载 作者:行者123 更新时间:2023-11-30 04:01:48 26 4
gpt4 key购买 nike

我尝试在 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");
....
}

最深的异常被抛出,但它不会继续到外部函数。程序终止。为什么?

最佳答案

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

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

关于c++ - 级联 Poco 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25564990/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com