Home > Backend Development > PHP Problem > How to display the number of error lines in php

How to display the number of error lines in php

青灯夜游
Release: 2023-03-12 17:52:01
Original
2340 people have browsed it

In PHP, you can use the getLine() function in the exception handling class Exception to display the number of error lines. This function can return the line number of the code where the error occurred. The syntax is "final public Exception::getLine() :int".

How to display the number of error lines in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

PHP provides a built-in exception handling class— —Exception, the member function getLine() in this class can return the code line number where the error occurred

Exception::getLine — Get the line number in the file where the created exception is located

Syntax:

final public Exception::getLine(): int
Copy after login

Return value: Returns the line number of the code where the error occurred.

Example:

<?php
header("Content-type:text/html;charset=utf-8");
try {
    throw new Exception("一些错误消息");
} catch(Exception $e) {
    echo "错误发生在第: " . $e->getLine()."行";
}
?>
Copy after login

Output result:

How to display the number of error lines in php

##Recommended learning: "

PHP Video Tutorial

The above is the detailed content of How to display the number of error lines in php. For more information, please follow other related articles on the PHP Chinese website!

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