2014-08-29 67 views
1

我嘗試在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"); 
    .... 
} 

引發最深的異常,但它不會繼續執行外部函數。 程序終止。爲什麼?

回答

2

你拋出一個Poco :: Exception指針,所以你不能通過引用來捕獲它。 刪除'新'。這應該工作:

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