Current Location: Home> Function Categories> getMessage

getMessage

Returns a string describing the reason for the exception being thrown.
Name:getMessage
Category:Uncategorized
Programming Language:php
One-line Description:Returns a string describing the reason for the exception being thrown.

Definition and usage

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

Related pages

Tutorial: PHP exception

Example

Throw an exception and output its message:

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

Try it yourself

grammar

 $exception -> getMessage ( )
Similar Functions
Popular Articles