PHP try Keyword

P
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

Tutor Network

Share this

Learn PHP from A to Z