我正在查看一些旧的遗留代码,并使用以下try / catch块 - 多次名称默认为' DEFAULTNAME' - 我不确定为什么要这样做?我认为尝试失败了(在这个例子中是xml的东西)&导致它默认为' DEFAULTNAME' (并不总是相当数量)
另外......所有尝试/捕获块都需要“扔”'太?由于此代码在任何地方都没有?
$xml_element = new SimpleXMLElement($xml);
$namespaces = $xml_element->getDocNamespaces();
$xml_element->registerXPathNamespace('tns', $namespaces['']);
$re = $xml_element->xpath('///tns:IntegrationExport/tns:Data/tns:Citizen/tns:Services/tns:Service[@refinement="Pupil"]');
$re_element = $re[0];
$re_element = $re_element[0];
// xml stuff...
try
{
// $re_element is collated from some xml/xpath query outside of the try/catch block via an API
$name = (string)$re_element->attributes()->application;
$name = strtolower($name);
$name = str_replace("Name ","",$name);
$name = trim($name);
}
catch(Exception $e)
{
$name = "DEFAULTNAME";
error_log($e->getMessage);
}