解决方案 »

  1.   

    require一个文件存在错误的话,那么程序就会中断执行了,并显示致命错误
    include一个文件存在错误的话,那么程序不会中端,而是继续执行,并显示一个警告错误。
      

  2.   

    include 可以用try-catch抛出及捕捉异常。<?php
    error_reporting(0);try{
        $flag = include "inc.php";
        if(!$flag){
            throw new Exception("include error", 1);
        }
    }catch(Exception $e){
        echo "inc.php not exists<br>";
    }echo 'do sth';
    ?>
      

  3.   

    如果使用require文件不存在,是fatal error,程序会中指。所以try-catch不适合。
    但可以用set_error_handle来设定出现错误后的处理动作。error_reporting(0);function handle($errno ,  $errstr ,  $errfile ,  $errline){
        echo 'inc.php not exits<br>';
        echo 'do sth';
    }set_error_handler('handle');require_once "inc.php";
      

  4.   

    如果 inc.php 写作<?php
    错误能抛出及捕捉异常吗?