Zend_Service_Technorati, Exceptions and partialLoop
I am utilizing Zend_Service_Technorati to tag search and when I return the results and loop through it via a partialLoop, an exception is thrown occasionally. One of the results does not have a valid uri and Zend_Uri_Http is throwing the exception based on the path (not sure whether Tehnorati is returning a invalid url or Zend_Uri_Http is declaring a valid url invalid). The problem is I am using partialLoop to dynamically loop through result sets other than Technorati, such as Youtube and Flickr, and it is nice just to call the appropriate partial based on the result set object.
However, there is no easy way to catch the Exception. If I wrap the entire partial loop in a try/catch, then it doesn’t display any results when there is an exception, even though there is only one offending result:
<?php
try {
echo $this->partialLoop(‘adminexternalmedia/_result’ . $this->collection->type . ‘.phtml’,$this->resultSet);
} catch(Exception $e) {
echo ‘problem’;
}
?>
I can’t catch the exception in the partial that handles the display, because the exception is created once the individual result is grabbed from the set and before the partial is “rendered” - i.e. triggered in the foreach call. Since the result sets implement SeekableIterator, I can use a while loop and call partial, instead of relying on the partialLoop, and handle my exception as I deem fit:
<?php
$this->partial()->setObjectKey(‘model’);
while($this->resultSet->valid()) {
try {
$result = $this->resultSet->current();
echo $this->partial(‘adminexternalmedia/_result’ . $this->collection->type . ‘.phtml’,$result);
} catch (Exception $e) {
echo ‘problem<br /><br />’;
}
$this->resultSet->next();
}
?>