try{
    file_get_contents($x_url);
}catch(Exception $e){
    print $e->getMessage();
    exit();
}或直接if(!file_get_contents($x_url)){
 echo '有错误发生。';
 exit();
}

解决方案 »

  1.   

    try{
    $error = file_get_contents($x_url);
    throw new Exception($error);}catch(Exception e){
    echo '捕捉异常: ',  $e->getMessage(), "\n";
    }
      

  2.   

    不好意思,上面漏了个$,现在补上catch(Exception $e)
      

  3.   

    <?php $string = @file_get_contents("index.html");
    print_r(error_get_last());
    //echo $string;
    ?>设置找不到 index.html 文件让程序出现警告看看...
      

  4.   

    专业点应该用 http client 类模拟正浏览动作...
      

  5.   


    try{ throw new Exception($error); }catch(Exception $e){ }
      

  6.   

    参考楼上意见,这样写编译通不过!Parse error: syntax error, unexpected '{' in c:\inetpub\wwwroot\vnstock\vnphp\try.php on line 4
    <?php
    $x_url = "index.html";
    try
    {
        $x_html=file_get_contents($x_url); 
    }
    catch(Exception $e)

        print $e->getMessage(); 
        exit(); 
    }
    echo $x_html;
    ?>
      

  7.   

    好像说PHP5才处理异常,我的是php4
      

  8.   

    是的,try..catch语句是PHP5新增加的。
    PHP4也是可以处理异常的,但不是这样,像一楼的就对了,他的第二种方法是正确的,像楼主用的file_get_contents,一般用if...else的语句,就行了(PHP4支持)。
      

  9.   

    try
    {
        
    }
    catch(Exception $e)

       
    }
      

  10.   

    error级别的都不需要捕获,因为你根本就不能编译允许