即使在致命错误:未捕获的异常之后也继续


Continue even after Fatal error: Uncaught exception

我正在查询谷歌API,它的上限低得离谱,只有100/天,我得到:

Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET ...

.. 并且脚本在那之后什么都不做。

如何防止它失败并至少保存到那时收到的任何数据?我正在将数据保存在一个数组中:

function searchImages($service, $optParams, $query) {
  $results = $service->cse->listCse($query, $optParams);
  return $results;
}
$descriptionSearch = searchImages($customsearchService, $customsearchService_optParams, $descriptions[$i]);
foreach ($descriptionSearch->items as $item) {
  array_push($list[$item_codes[$i]], strtok($item->link,'?'));
}
function searchImages($service, $optParams, $query) {
  try {
      $results = $service->cse->listCse($query, $optParams);
  }catch (Exception $e) {
      // should log this exception... you can use Log4PHP
      return NULL;
  }
  return $results;
}
$descriptionSearch = searchImages($customsearchService,customsearchService_optParams, $descriptions[$i]);
if (!is_null($descriptionSearch)) {
    foreach ($descriptionSearch->items as $item) {
        array_push($list[$item_codes[$i]], strtok($item->link,'?'));
    }
}