Home > Backend Development > PHP Tutorial > php predefined exception

php predefined exception

伊谢尔伦
Release: 2016-11-22 11:07:11
Original
1077 people have browsed it

1.Exception

(PHP 5 >= 5.1.0)

Introduction

Exception is the base class of all exceptions.

Method

Exception::__construct — Exception constructor

Exception::getMessage — Get the exception message content

Exception::getPrevious — Return the previous exception in the exception chain

Exception::getCode — Get the exception code

Exception::getFile — Get the name of the program file where the exception occurred

Exception::getLine — Get the line number of the code in the file where the exception occurred

Exception::getTrace — Get the exception tracking information

Exception::getTraceAsString — Get Exception tracking information of string type

Exception::__toString — Convert exception object to string

Exception::__clone — Exception cloning

2.ErrorException

(PHP 5 >= 5.1.0)

Introduction

Error exception.

Example

Example #1 Use the set_error_handler() function to host error information to 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();
?>
Copy after login

The output of the above routine is similar to:

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
Copy after login

method

ErrorException::__construct — exception constructor

ErrorException::getSeverity — Get exception severity


Related labels:
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