Forum Moderators: coopster

Message Too Old, No Replies

error handling...

         

scorpion

2:06 pm on Apr 10, 2003 (gmt 0)

10+ Year Member



Hi, I'm trying to embed error handling in my fopen routine, I use fopen to open a remote resource. Basically, if ANYTHING goes wrong, the http resource fails, etc.., I want to be able to get an error code and do a different action, what would this control structure look like?

mavherick

5:40 pm on Apr 10, 2003 (gmt 0)

10+ Year Member



I'm not to sure about error code, but you could implement something like this to catch any failure:

$handle = @fopen("http://some.resource.com","r") OR your_error_handling_routine("fopen failure");

the "@" in front of fopen will prevent fopen to output any error message to the browser and you can handle it in your own defined function.

I remember seeing a class for error handling somewhere on the net, if I can find it, I'll let you know.

mavherick

<added>found it DevShed [devshed.com]</added>

scorpion

7:02 pm on Apr 10, 2003 (gmt 0)

10+ Year Member



thanks, I had the situation that a remote site went down and my php script, depending on it, starting in a recursive loop to print out <fopen error...> etc.. on the page in which the fopen call was made.

So the @ will supress these messages and load my current page EXCEPT the php areas of the page? or it will just show blank for the whole page?

I mean that the page has a bit of php code embedded in it but it is not 100% of the html

mavherick

7:21 pm on Apr 10, 2003 (gmt 0)

10+ Year Member



Well if you use the statement like this:

$handle = @fopen("http://someresource","r");

if($handle)
{
// display resource content
} else {
// display a nice little message like resource down check back later or even leave it blank
}

it won't terminate your script, everything else that is not based on the handler will work.

mavherick