PHP throw Keyword

❮ PHP Keywords

Example

Throw an exception:

<?php
try {
  throw new Exception("This is an exception");
} catch(Exception $e) {
  echo $e->getMessage();
}
?>
Try it Yourself »

Definition and Usage

The throw keyword is used to throw exceptions. Exceptions are a way to change the program flow if an unexpected situation arises, such as invalid data.

The try...catch...finally structure can be used to handle exceptions.


Related Pages

The try keyword.

The catch keyword.

The finally keyword.

Read more about try..catch.finally (Exceptions) in our PHP Exceptions Tutorial.


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