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

How to display the number of error lines in php

青灯夜游
青灯夜游Original
2021-09-18 15:12:402311browse

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

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()."行";
}
?>

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!

Statement:
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