PHP try Keyword

PHP use Keyword
PHP trait Keyword

In this article, you will learn how to declare try catch block in PHP. The try keyword in PHP is used to create a try…catch, or a try…catch…finally statement.

examples of the TRY keyword

Example 1. In this example, we use a try…catch statement to handle exceptions.

<?php
try {
  throw new Exception("This is an exception");
} catch(Exception $e) {
  echo $e->getMessage();
}
?>
PHP use Keyword
PHP trait Keyword

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top