Reputation: 53
In case a request cannot be made, how can I catch the exception?
I have so far written this, but not had any luck.
$url = 'http://localhost:49000/';
//create the httprequest object
try{
$httpRequest_OBJ = new httpRequest($url, HTTP_METH_POST, $options);
}catch(HttpException $e){
echo $e;
}
Upvotes: 0
Views: 4356
Reputation: 187
I had the same problem, you should make sure that the exception is in the namespace.
What I've done is:
try {
//Request here
} catch (\HttpException $e) {
//Handle exception
} catch (\Exception $e) {
//Just in case
}
Also good to notice what is pointed in this article http://www.mkfoster.com/2009/01/06/how-to-pecl-http-request-exception-and-error-handling/ about the inner exception, in case you want the message returned by the exception.
Also, there is a php.ini directive that forces HttpRequest to always throw exception http://br.php.net/manual/en/http.configuration.php http.only_exceptions=1
Upvotes: 1
Reputation: 197777
how can I catch the exception?
To catch an exception you need to know the classname of the exception. What is the classname of the exception you'd like to catch?
Upvotes: 0