【发布时间】:2012-04-11 23:37:15
【问题描述】:
我无法捕捉 Zend 异常。看起来 Zend 有自己的异常处理,不会重新抛出异常。然后结果我得到了带有异常描述的白屏。有什么办法可以捕捉并很好地展示吗?
$client = new Zend_Rest_Client($url);
// Get instance of Zend_Http_Client
$httpClient = $client->getHttpClient();
// Change the timeout
$httpClient->setConfig(array(
"timeout" => 0.1 // This is just for test
));
try {
$restClientResult = $client->get();
} catch (Zend_Rest_Client_Result_Exception $e) {
doSomething(); // <- is not entered here
}
错误是:
An error occurred
Exception information:
Message: Unable to Connect to ssl://localhost/resource:443. Error #110: Connection timed out
Stack trace:
#0 /.../lib/Zend/Http/Client.php(974): Zend_Http_Client_Adapter_Socket->connect('localhost/resour...', 443, true)
#1 /.../lib/Zend/Rest/Client.php(137): Zend_Http_Client->request('GET')
...
【问题讨论】:
-
看起来有一个您没有发现的不同类型的异常。尝试
catch (Exception $e) { var_dump(get_class($e));确定这是什么类型的异常。 -
想通了。我正在捕捉 Zend_Rest_Client_Result_Exception。将其更改为 Zend_Exception,现在可以了。 @Niko,谢谢,我们得出了相同的结论 :) 请回答问题,以便我将其标记为解决方案。
标签: php http zend-framework exception try-catch