unkwntech Posted July 15, 2010 Share Posted July 15, 2010 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 More sharing options...
Mchl Posted July 15, 2010 Share Posted July 15, 2010 Because error is not an exception. See Example #1 here on how to convert errors to exceptions Link to comment https://forums.phpfreaks.com/topic/207869-trycatch-not-functioning-as-expected/#findComment-1086664 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.