Re: Exception handling with file()

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

 



2008. 02. 11, hétfő keltezéssel 14.34-kor John Papas ezt írta:
> I need to open a remote file with file() and I would like to put it
> inside a try-catch but as far as I can tell file() does not raise an
> exception if it fails. The following code:
> 
> 	try {
> 	   $data = file('http://myserver.com/myfile.txt');
	$data = @file('http://myserver.com/myfile.txt');
	if ($data === FALSE) throw new Exception('whatever');


hope that helps
Zoltán Németh

> 	   $date = substr($data, 0);
> 	} catch (Exception $e) {
> 	   $data = "it failed";
> 	}
> 	
> 	echo $data;
> 
> echoes a warning:
> 
> 	Warning: file('http://myserver.com/myfile.txt') [function.file]:
> failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
> in.....
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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