我無法弄清楚如何從拋錨處理器中拋出一個異常。 這裏是我的代碼:GuzzleHttp異步請求異常
<?php
require 'vendor/autoload.php';
$client = new \GuzzleHttp\Client();
$req = $client->createRequest('GET', 'http://www.google.com', array(
'future' => true,
));
echo "Sending request\n";
$response = $client->send($req);
try {
$response->then(function ($data) {
echo "Response is received\n";
throw new Exception('Test');
})->then(function() {
// success handler
}, function (Exception $exception) {
echo "Error handler invoked\n";
throw $exception;
});
} catch (Exception $e) {
echo "Exception catched\n";
}
echo "Finish\n";
的catch
塊是從來沒有在這種情況下達成。
謝謝,現在很清楚。 – 2014-10-29 07:55:02
@MichaelDowling是否GuzzleHttp \ Promises仍然吃例外? – 2016-12-30 09:02:57