Home > Backend Development > PHP Tutorial > php expection and how to find php errors

php expection and how to find php errors

WBOY
Release: 2016-06-23 14:35:37
Original
895 people have browsed it

代码

                  <p class="sycode">                      <     ?     php     //      例[2] try..cathc 和 throw一起用          try      {     $error           =           '     我抛出异常信息,并且跳出try块     '     ;     if     (     is_dir     (     '     ./tests     '     )){     echo           '     do sth.     '     ;}     else     {      throw           new           Exception     (     "     出现了异常     "     ); PHP中的异常必须要进行显式的抛出 }     echo           '     上面有异常的话就轮不到我了!~<br />     '     ,     "     \n     "     ;}      catch      (     Exception           $e     ) {  显示输出错误的相关数据与资料      echo           '     捕获异常:      '     ,           $e     -     >getMessage();      echo           $e     -     >getCode()     ,           "     \n<br />     "     ; 显示错误代码的      echo           $e     -     >getLine()     ,           "     \n<br />     "     ; 显示错误代码的行号      echo           $e     -     >getFile()     ,           "     \n<br />     "     ; 显示异常所产生的文件 }     echo           '     继续执行     '     ;     ?     >                  </p>
Copy after login

注意: 在PHP中的异常体系中,所有的异常必须要进行显式的抛出. 这是很不同于java开发的

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template