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

Exception::getMessage

PHP function Edit on GitHub ✎

(PHP 5, PHP 7, PHP 8)

Gets the Exception message

Description

Exception::getMessage(): string

Returns the Exception message.

Parameters Parameters

Return Values

Returns the Exception message as a string.

Examples

Exception::getMessage() example

php
<?php
try {
    throw new Exception("Some error message");
} catch(Exception $e) {
    echo $e->getMessage();
}
?>

The above example will output something similar to:

output
Some error message

See Also

  • Throwable::getMessage

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