Jump to content

Try{}Catch{} not functioning as expected


unkwntech

Recommended Posts

I have the following code.  'hello.php' is a file that does not exist, and as expected require_once is throwing an error:


Warning: require_once(template/pages/hello.php) [function.require-once]: failed to open stream: No such file or directory in /var/www/public_html/index.php on line 26

Fatal error: require_once() [function.require]: Failed opening required 'template/pages/hello.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/public_html/index.php on line 26

 

However the catch statement is never happening, what am I doing wrong?

$page = 'hello';


//If the page that was requested does not exist then load an error page showing a 404
try
{
require_once 'template/pages/' . $page . '.php';
}
catch(Exception $e)
{
//TODO: send a status code 404
require_once 'template/pages/error/404.php';
}

Link to comment
https://forums.phpfreaks.com/topic/207869-trycatch-not-functioning-as-expected/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.