php8.5
Home/ Manual/ predefined / exception/ Exception::getLine

Exception::getLine

PHP function Edit on GitHub ✎

(PHP 5, PHP 7, PHP 8)

Gets the line in which the exception was created

Description

Exception::getLine(): int

Get line number where the exception was created.

Parameters Parameters

Return Values

Returns the line number where the exception was created.

Examples

Exception::getLine() example

php
<?php
try {
    throw new Exception("Some error message");
} catch(Exception $e) {
    echo "The exception was created on line: " . $e->getLine();
}
?>

The above example will output something similar to:

output
The exception was created on line: 3

See Also

  • Throwable::getLine

Source: language/predefined/exception/getline.xml · from the official PHP manual (php/doc-en)