php错误异常处理

一、错误分类

 notice:提醒有错
 waning:警告错误,不会终止程序运行
 error:致命错误,程序无法继续运行

二、程序在执行过程中常见的错误

; E_ALL             - All errors and warnings (includes E_STRICT as of PHP 5.4.0)
; E_ERROR           - fatal run-time errors
; E_RECOVERABLE_ERROR  - almost fatal run-time errors
; E_WARNING         - run-time warnings (non-fatal errors)
; E_PARSE           - compile-time parse errors
; E_NOTICE          - run-time notices (these are warnings which often result
;                     from a bug in your code, but it's possible that it was
;                     intentional (e.g., using an uninitialized variable and 
;                     relying on the fact it is automatically initialized to an
;                     empty string)
; E_STRICT          - run-time notices, enable to have PHP suggest changes
;                     to your code which will ensure the best interoperability
;                     and forward compatibility of your code
; E_CORE_ERROR      - fatal errors that occur during PHP's initial startup 
; E_CORE_WARNING    - warnings (non-fatal errors) that occur during PHP's
;                     initial startup
; E_COMPILE_ERROR   - fatal compile-time errors
; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
; E_USER_ERROR      - user-generated error message
; E_USER_WARNING    - user-generated warning message
; E_USER_NOTICE     - user-generated notice message
; E_DEPRECATED      - warn about code that will not work in future versions
;                     of PHP
; E_USER_DEPRECATED - user-generated deprecation warnings

三、屏蔽错误

  1. 修改ini.php配置文件: display_errors为(off)–屏蔽错误
  2. 修改ini.php配置文件:error_reporting选项,可以定义任意类型错误输出或者不输出
    • 默认:error_reporting: E_ALL 显示全部错误
    • 自定义任意类型错误:
      • 如:error_reporting: E_ALL & ~E_NOTICE & ~E_USER_NOTICE
        解释:&用以连接多个错误;~表示不包括
  3. 在php文档中通过使用’@’ 错误抑制符:
    在出错的哪一行添加,即可实现错误屏蔽,但是只能屏蔽单行错误、效率低
  4. 在php文档中通过使用函数实现屏蔽:error_reporting( )
    如:error_reporting( E_ALL & ~E_NOTICE & ~E_USER_NOTICE);

四、不在浏览器中显示,生成错误日志

在ini.php配置文件中以此实现以下步骤:
  1. 修改ini.php配置文件: display_errors为(off)–屏蔽错误
  2. 修改ini.php配置文件:error_reporting选项,定义任意类型错误输出或者不输出
  3. 开启错误日志提醒开关:log_errors = on
  4. 设置错误日志存放地点:
    a)存放在系统错误日志中:error_log = syslog
    - 通过打开电脑里”事件查看器”查看:控制面板 –> 管理工具 –> 事件查看器 –>Windows日志 –>应用程序
    b)自定义存放路径:error_log = “自定义错误日志输出的路径”
    如:error_log = "E:/logs/php_error.log"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值