PHP try Keyword
Example
Use a try...catch statement to handle exceptions:
<?php
try {
throw new Exception("This is an exception");
}
catch(Exception $e) {
echo $e->getMessage();
}
?>
Try it Yourself »
Definition and Usage
The try
keyword is used to create a try...catch
, or a try...catch...finally
statement.
Related Pages
The throw
keyword.
The catch
keyword.
The finally
keyword.
Read more about try..catch.finally (Exceptions) in our PHP Exceptions Tutorial.
❮ PHP Keywords