Re: Best error handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



No luck with your solution... I think that the only way is (as you said) to
make sure that there will be no fatal errors :)
I'll will implement the error handler as well (to catch some minor errors)
and uncaught exceptions.

The method for catch all errors using a shutdown function appears to work,
but it crashes when using my php stream "mock" implementation (that I use to
simulate calls to the script).

Thanks anyway Nathan!

PS. Is there some plan to make PHP full exception-ready, dropping the usual
way of return values?

Davi

On Fri, Feb 27, 2009 at 9:51 PM, Nathan Rixham <nrixham@xxxxxxxxx> wrote:

> 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
>



-- 
Davi R. Tavares

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux