Page 1 of 1

Please Help::: FATAL Error handling

Posted: Tue Jul 08, 2003 10:27 am
by zoltarb
Hi,
Im a PHP newbie. could anyone please help me out regarding error handling in PHP. I've searched so many sites that talk abt Error handling, but when it comes to handling fatal errors theres nothing and even if there is, it is not that descriptive.
Being a Java programmer, its really frustrating when it comes to handling errors in PHP. But Im not giving up :)

regards,
zoltarb

Posted: Tue Jul 08, 2003 1:05 pm
by cactus
Have you read :

Ref : XXVI. Error Handling and Logging Functions
http://uk2.php.net/errorfunc

Ref : set_error_handler
http://uk2.php.net/manual/en/function.s ... andler.php

Regards,

Fatal Error Handling

Posted: Tue Jul 08, 2003 2:24 pm
by zoltarb
Yes, I've looked into all the possible examples i could find on the net for handling fatal errors. but most of them are handled by trigger_error() functions. Isnt there any other way to capture these fatal errors and show the user with some message.
like for eg:

<?php
$test = 0;
while( true ){
$test *= 1000;
}

?>
(Ofcourse i wouldnt write such a code in my script, this is just to create some fatal error)Now when i execute this script it ofcourse gives me a fatal error for execution timeout.
Is there some way to capture this error and show some user friendly message?????

Thanks in advance.

Regards,
zoltarb

Re: Fatal Error Handling

Posted: Tue Jul 08, 2003 2:35 pm
by cactus
zoltarb wrote:Is there some way to capture this error and show some user friendly message?????
I do believe this is what you need, the only way (I know of) you can output non-standard error messages is with the use of:
cactus wrote:Ref : set_error_handler
http://uk2.php.net/manual/en/function.s ... andler.php
For example, if you had the script (in manual page above) as an include/require on all your pages, it would handle your exceptions, if you have "display_errors" set to "On".

Or am I misunderstanding your issue ?

Regards,

Posted: Tue Jul 08, 2003 3:10 pm
by SBukoski
I think he is looking for something along the lines of a Try|Except block. As far as I know, there really is no good way of doing this in PHP 4 that is built-in. All the ones people have used have been home grown. One of the features of PHP 5 is the addition of a Try|Catch block that will allow you to do error checking and error handling much more easily than in the past.

Fatal Error Handling

Posted: Wed Jul 09, 2003 4:27 am
by zoltarb
Something like TRY|Catch exception handling is what I'm looking for. but since PHP4 doesnt support it, is there a workaround for that. I have tried including that script for set_error_handler in all the pages...but doesnt seem to work for fatal errors :(

Please Help!!
Thanks in advance

regards,
zoltarb

Posted: Wed Jul 09, 2003 7:22 am
by jason
Several things:

First, Exception handling will be in PHP5. Until then, your pretty much sunk.

Next, Fatal errors are fatal. "These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted." See, here the problem. Someone sets a script execution time of 30 seconds. Your script runs for 30 seconds with that loop. After that, it dies. It CAN'T let you handle the error, because then it would give back user control, and you could extend the execution time of the script, which would mean their's no sense in having a max execution time. However, you can always increase this time in php.ini.

Next, PHP has good error handling already. The problem is your trying to deal with fatal errors. You compare it to Java. Well, in PHP, a fatal error is basically the same thing as a Java programming not compiling to byte code.

If a Java program can't compile down to byte code, it won't run. PHP is sort of the same way. PHP can't run the error handler because the error is fatal. Fatal errors should NOT exist in production code. How could you catch an error for a missing semi-colon? It's a syntax error, it's fatal. It was never compiled to op-code, their is no way it could run.

Becareful about comparing PHP to Java. It's like comparing a 18-wheeler to a Mercedes. They do things differently.

Posted: Fri Jul 11, 2003 8:04 am
by zoltarb
thanks jason, guess will wait for PHP5 :)