我尝试捕获异常,但我仍然收到“致命错误:未捕获的异常 'GuzzleHttp\Exception\ClientException' 并在 C:\OS\OpenServer\domains\kinopoisk\parser\php\vendor\guzzlehttp\ 中显示消息 'Client error: 404' guzzle\src\Middleware.php:69"
<?php
ini_set('display_errors', 'on');
error_reporting(E_ALL);
set_time_limit(0);
require "vendor/autoload.php";
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\ClientException;
$filmsUrl = [297, 298];
$urlIterator = new ArrayObject($filmsUrl);
$client = new Client([
'base_uri' => 'http://example.com',
'cookies' => true,
]);
foreach ($urlIterator->getIterator() as $key => $value) {
try {
$promise = $client->requestAsync('GET', 'post/' . $value, [
'proxy' => [
'http' => 'tcp://216.190.97.3:3128'
]
]);
$promise->then(
function (ResponseInterface $res) {
echo $res->getStatusCode() . "\n";
},
function (RequestException $e) {
echo $e->getMessage() . "\n";
echo $e->getRequest()->getMethod();
}
);
} catch (ClientException $e) {
echo $e->getMessage() . "\n";
echo $e->getRequest()->getMethod();
}
}
$promise->wait();
我的代码有什么问题?