发生错误时,打开文本文件不会自动抛出错误

时间:2014-08-08 14:33:06

标签: php exception exception-handling error-handling throw

在运行时错误发生时不抛出错误吗?

例如$errorMsg

的剂量不存在fwrite($logFile,$errorMsg);

或剂量不存在dirname(__FILE__).'\a\logError.txt

在此代码中没有运行er()而没有运行cache ???

将显示php默认消息!

function er()
{
    echo "error.....";
}

try
{
        set_exception_handler('er');


        $logFile=fopen(dirname(__FILE__).'\a\logError.txt','w');        
        fwrite($logFile,$errorMsg);
        fclose($logFile);

}
catch(Exception $e)
{
    echo $e->getMessage();
    echo "catch";   
}   


Warning: fopen(C:\xampp\htdocs\HidariGold\a\logError.txt) [function.fopen]: failed to open stream: No such file or directory in C:\xampp\htdocs\HidariGold\test.php on line 35

Notice: Undefined variable: errorMsg in C:\xampp\htdocs\HidariGold\test.php on line 36

Warning: fwrite() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\HidariGold\test.php on line 36

Warning: fclose() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\HidariGold\test.php on line 37

那么try{}catch{} ??????????

的好处是什么?

0 个答案:

没有答案