Example
Throw an exception:
html
<?php
try {
throw new Exception("This is an exception");
}
catch(Exception $e) {
echo $e->getMessage();
}
?>
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.