PHPthrow Keyword
Example
Throw an exception:
<?php
try {
throw new Exception("This is an exception");
} catch(Exception $e) {
echo $e->getMessage();
}
?>
Try it Yourself »try {
throw new Exception("This is an exception");
} catch(Exception $e) {
echo $e->getMessage();
}
?>
Definition and Usage
Thethrow keyword is used to throw exceptions. Exceptions are a way to change theprogram flow if an unexpected situation arises, such as invalid data.
Thetry...catch...finally structure can be used to handle exceptions.
Related Pages
Thetry keyword.
Thecatch keyword.
Thefinally keyword.
Read more about try..catch.finally (Exceptions) in ourPHP Exceptions Tutorial.
❮ PHP Keywords

