note 51205 added to language.exceptions
| From: | BillKuker at osu1 dot php dot net | Date: | Wed, 23 Mar 2005 14:10:15 +0000 |
| Subject: | note 51205 added to language.exceptions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-86843@lists.php.net to get a copy of this message | ||
In an application made of many pages each of which includes a standard header and footer I found
myself wanting to be able to define a top level try / catch block with a default error screen.
Unfortunatly you cant put 'try{' in header.inc and '}catch...' in footer.inc. My
solution is to do away with the footer and just require_once a header.inc that looks like this:
//Output header
try{
ob_start();
include($_SERVER['PHP_SELF']);
ob_end_flush();
} catch (Exception $e){
ob_end_clean();
//error screen
}
//Output Footer
die();
This in effect wraps the including page in the try / catch block. Note the importance of where I
require_once vs where I include, and that you would not want to run header.inc directly ;)
----
Manual Page -- http://www.php.net/manual/en/language.exceptions.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51205
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51205&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51205&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51205&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51205&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51205&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51205&report=yes
Search -- http://master.php.net/manage/user-notes.php