时间:2021-07-01 10:21:17 帮助过:4人阅读
1.Exception
(PHP 5 >= 5.1.0)
简介
Exception是所有异常的基类。
方法
Exception::__construct — 异常构造函数
Exception::getMessage — 获取异常消息内容
Exception::getPrevious — 返回异常链中的前一个异常
Exception::getCode — 获取异常代码
Exception::getFile — 获取发生异常的程序文件名称
Exception::getLine — 获取发生异常的代码在文件中的行号
Exception::getTrace — 获取异常追踪信息
Exception::getTraceAsString — 获取字符串类型的异常追踪信息
Exception::__toString — 将异常对象转换为字符串
Exception::__clone — 异常克隆
2.ErrorException
(PHP 5 >= 5.1.0)
简介
错误异常。
范例
Example #1 使用 set_error_handler()函数将错误信息托管至ErrorException
<?php
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exception_error_handler");
/* Trigger exception */
strpos();
?>以上例程的输出类似于:
Fatal error: Uncaught exception 'ErrorException' with message 'Wrong parameter count for strpos()' in /home/bjori/tmp/ex.php:8
Stack trace:
#0 [internal function]: exception_error_handler(2, 'Wrong parameter...', '/home/bjori/php...', 8, Array)
#1 /home/bjori/php/cleandocs/test.php(8): strpos()
#2 {main}
thrown in /home/bjori/tmp/ex.php on line 8方法
ErrorException::__construct — 异常构造函数
ErrorException::getSeverity — 获取异常的严重程度