I’m trying to catch an error
try
{
$outcome = $bet->getElementsByTagName("Outcome");
$line1 = $outcome->item(0)->getElementsByTagName("OptionalValue1")->item(0)->nodeValue;
$line2 = $outcome->item(2)->getElementsByTagName("OptionalValue1")->item(0)->nodeValue;
$aOdds["line"] = ($line1 == 0) ? -$line2 : $line1;
$aOdds["q1"] = $outcome->item(0)->getAttribute("odds");
$aOdds["qx"] = $outcome->item(1)->getAttribute("odds");
$aOdds["q2"] = $outcome->item(2)->getAttribute("odds");
}
catch (Exception $e)
{
$outcome = $bet->getElementsByTagName("Outcome");
$line1 = $outcome->item(0)->getElementsByTagName("OptionalValue1")->item(0)->nodeValue;
$line2 = $outcome->item(1)->getElementsByTagName("OptionalValue1")->item(0)->nodeValue;
$aOdds["line"] = ($line1 == 0) ? -$line2 : $line1;
$aOdds["q1"] = $outcome->item(0)->getAttribute("odds");
$aOdds["qx"] = 0;
$aOdds["q2"] = $outcome->item(1)->getAttribute("odds");
}
Some data comes with 2 same tag and the others with 3 and I want to catch if there not exist the 3. tag, but the error catching not really work.
You should read a little more about the concept of exceptions. Here are a few links that you might find useful:
http://www.w3schools.com/php/php_exception.asp
http://ciaweb.net/pear-exception-use-guidelines.html
http://php.net/manual/en/language.exceptions.php