Posted by Hans 'pritaeas' Pollaerts on 08/09/06 16:24
"Pugi!" <reply@group.svp> wrote in message
news:lvmdnZfd_o9vnUfZRVnyrQ@scarlet.biz...
> Hi,
> How can you catch a fatal error that occurs when you use a
> require_once("myfile.php") and the file dioesn't exist ?
> I tried:
> try {
> require_once("p.php");
> } catch (Exception $e) {
> echo $e->getMessage();
> }
> but it returns
> Warning: require_once(p.php) [function.require-once]: failed to open
stream:
> No such file or directory in D:\apache\xampp\htdocs\site\untitled.php on
> line 12
>
> Fatal error: require_once() [function.require]: Failed opening required
> 'p.php' (include_path='.;D:\apache\xampp\php\pear\') in
> D:\apache\xampp\htdocs\site\untitled.php on line 12
>
> So the try/catch is in fact completely ignored.
>
> Pugi!
>
>
You can replace it with:
<?php
if (file_exists ("p.php")) require_once ("p.php");
?>
Navigation:
[Reply to this message]
|