PHP Exception getMessage() Method

❮ PHP Exception Reference

Example

Throw an exception and then output its message:

<?php
try {
  throw new Exception("An error occurred");
} catch(Exception $e) {
  echo $e->getMessage();
}
?>
Try it Yourself »

Definition and Usage

The getMessage() method returns a description of the error or behaviour that caused the exception to be thrown.


Syntax

$exception->getMessage()

Technical Details

Return Value: Returns a string

Related Pages

Read more about Exceptions in our PHP Exceptions Chapter.


❮ PHP Exception Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.