Re: Best error handling
| From: | Nathan Rixham | Date: | Sat, 28 Feb 2009 00:51:45 +0000 |
| Subject: | Re: Best error handling | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-288963@lists.php.net to get a copy of this message | ||
Davi Ramos wrote:
Hi. I have a kind of webserver that certain applications communicate with. The problem is that the script (named peer.php) must output data as xml. Thats ok (thanks to XMLWriter). The problem is that when some error occurs (those note catchable by set_error_handler) I have no control on data being outputed. I would like to output xml even on fatal errors (in that case, telling that something gone wrong). I tried using register_shutdown_function but it is crashing (as the nature of fatal errors that make the envirionment unstable). Any idea? Thanks!not a nice answer but make sure you're application has no fatal errors - a fatal error halts the compiler as it's fatal, thus there is no way to implement anything else afterwards or turn it in to an exception or suchlike. further, for live servers you really should have display errors set to off in you're php.ini - at which point nothing will be returned try: (not tested or particularly thought about) 1: move all the code from peer.php in to an include file 2: make you're main peer.php file contain only <?php try { require_once 'include_file.php'; } catch($e) { echo 'some xml error'; } ?> can't promise that'll work though, to test quickly just add all that to a php file and run it (as you don't have the required file so a fatal will get raised) regards and good luck - nathan ps: may check this one out myself, sure I've done it years ago when i still made sites