Heim  >  Artikel  >  Backend-Entwicklung  >  php预定义异常

php预定义异常

伊谢尔伦
伊谢尔伦Original
2016-11-22 11:07:11991Durchsuche

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 &#39;ErrorException&#39; with message &#39;Wrong parameter count for strpos()&#39; in /home/bjori/tmp/ex.php:8
Stack trace:
#0 [internal function]: exception_error_handler(2, &#39;Wrong parameter...&#39;, &#39;/home/bjori/php...&#39;, 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 — 获取异常的严重程度


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn