jordanwb Posted December 11, 2007 Share Posted December 11, 2007 <? try { $this->html = file_get_contents ($this->file); } catch (Exception $e) { } ?> This section of code is in a class and $this->file is defined. It has the value of "http://google.ca/url?sa=p" (no quotes). file_get_contents throws the following exception: Warning: file_get_contents(http://google.ca/url?sa=p) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 204 No Content in C:\xampp\htdocs\jproxy\includes\file_parser.php on line 27 So what I'm wondering is how come catch isn't catching the exception? Quote Link to comment Share on other sites More sharing options...
trq Posted December 11, 2007 Share Posted December 11, 2007 Unlike most languages, PHP generated exceptions are not caught by catch. You would need to use something like... <?php try { if (!$this->html = file_get_contents ($this->file)) { throw new exception("failed to open {$this->file}"); } } catch (Exception $e) { echo "Exception caught: {$e->message}"; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.