Zend在我之前捕获所有异常?

时间:2012-03-28 11:24:05

标签: php http zend-framework exception try-catch

我在捕获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')

...

1 个答案:

答案 0 :(得分:3)

解决方案(请参阅问题评论以获得解释):

try {
    $restClientResult = $client->get();
} catch (Zend_Exception $e) {
    doSomething();
}