This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

PHP Exceptions

The try...catch...finally Statement

An exception was thrown but not caught. The finally statement displays the process is complete but the rest of the page is not loaded.

<?php
// this code throws an exception
function divide($dividend, $divisor) {
  if($divisor == 0) {
    throw new Exception("Division by zero");
  }
  return $dividend / $divisor;
}

// the code is tried but the exception is not caught, "finally" signals the process is complete although the exception was not caught causing a fatal error
try {
  echo divide(5, 0);
} finally {
  echo 'Process complete.';
}
?>

Process complete.