刚从aspx转过来,还是总爱用那个思想考虑问题... 
具体到这个问题,我的代码:try
{
 preg_match_all($pattern,$string,$all);
}
catch (Exception $ex)

 echo $ex->getTraceAsString();
}
我是想如果有异常,就显示一下忽略掉,但还是显示出来警告,为什么呢···警告如下
Warning: preg_match_all() [function.preg-match-all]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'UTC' for '8.0/no DST' instead in F:\php\doom\newfile.php on line 52Warning: preg_match_all() [function.preg-match-all]: Empty regular expression in F:\php\doom\newfile.php on line 52 

解决方案 »

  1.   

    请分清楚警告和Exception的区别。PHP中的Warning和Error是PHP提醒开发者程序存在的问题,这个问题不一定要被处理
    Exception是属于应用程序中开发自定义,并且要处理的问题,原则上讲Exception是一定要有对应处理的
      

  2.   

    也就是说try/catch根本捕获不到这种 warning喽... 可warning虽然能忽略,但是会显示在网页上很难看的说,肯定不能忍受的,像这种情况,怎么才能真正的“忽略”呢...
      

  3.   

    error_reporting(0);或者在php.ini中设置error_reporting = 0;
      

  4.   

    异常抛出机制是php5才有的,所以只有在php5支撑下开发的扩展库才会有此机制。否则将沿袭php传统的错误处理机制。
    与.net不同,php的扩展库不是一家完成的,而是众多php支持者们的奉献。
    考虑到php4依然在升级,所以指望perg扩展库的开发者专为php5写一个扩展是不现实的。
    注意:php4与php5有着完全不同的内核
    设置 error_reporting 的值可以有不同的错误显示级别
    不想设置的话可在出错函数前加 @ ,当然你需要知道这样做的后果
    比较感兴趣的是:你给了 preg_match_all 什么样的参数而导致出现这样的提示