try{
file_get_contents($x_url);
}catch(Exception $e){
print $e->getMessage();
exit();
}或直接if(!file_get_contents($x_url)){
echo '有错误发生。';
exit();
}
file_get_contents($x_url);
}catch(Exception $e){
print $e->getMessage();
exit();
}或直接if(!file_get_contents($x_url)){
echo '有错误发生。';
exit();
}
$error = file_get_contents($x_url);
throw new Exception($error);}catch(Exception e){
echo '捕捉异常: ', $e->getMessage(), "\n";
}
print_r(error_get_last());
//echo $string;
?>设置找不到 index.html 文件让程序出现警告看看...
try{ throw new Exception($error); }catch(Exception $e){ }
<?php
$x_url = "index.html";
try
{
$x_html=file_get_contents($x_url);
}
catch(Exception $e)
{
print $e->getMessage();
exit();
}
echo $x_html;
?>
PHP4也是可以处理异常的,但不是这样,像一楼的就对了,他的第二种方法是正确的,像楼主用的file_get_contents,一般用if...else的语句,就行了(PHP4支持)。
{
}
catch(Exception $e)
{
}