只懂得try{ }catch(){ },具体怎么用,,,不知道
try {
    $aa=20/0;
} catch(Exception $ex) {
    echo 'Error:'.$ex->getMessage().'<br>';
   // echo $ex->getTraceAsString().'<br>';
}比如上面的代码20除以0.这个0是传进来的参数的话。具有不确定行。可能会导致不能除的情况。会报错,让程序崩溃,try catch拦截下。让程序继续。当然尽量不要有异常,你说这段的0,可以提前判断。不较真。。。举例子呢。。
就是捕捉异常 参考一下 下面的例子
PHP code
<?php
/*
 * 
 * opcode number: 107
 */
try {
    $error = 'Always throw this error';
    throw new Exception($error);
    // Code following an exception is not executed.
    echo 'Never executed';
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}
// Continue execution
echo 'Hello World';
?>