PHP Velho Oeste 2024

Exception::getLine

(PHP 5, PHP 7, PHP 8)

Exception::getLineObtém a linha na qual a exceção foi criada

Descrição

final public Exception::getLine(): int

Retorna o número da linha onde a exceção foi disparada.

Parâmetros

Esta função não possui parâmetros.

Valor Retornado

Retorna o número da linha onde a exceção foi disparada.

Exemplos

Exemplo #1 Exemplo da Exception::getLine()

<?php
try {
throw new
Exception("Alguma mensagem de erro");
} catch(
Exception $e) {
echo
"A exceção foi criada na linha: " . $e->getLine();
}
?>

O exemplo acima produzirá algo semelhante a:

A exceção foi criada na linha: 3

Veja Também

add a note add a note

User Contributed Notes 1 note

up
0
Festus Ngor
4 years ago
Exception::getTraceAsString — Gets the stack trace as a string. So use $e->getTraceAsString() i.e.:

<?php
try {
    throw new
Exception("Some error message");
} catch(
Exception $e) {
    echo
"The exception was created from: \n\r" . $e->getTraceAsString();
}
?>
To Top