Exceptions

An exception signals an abnormal situation without following the normal flow of the program. You throw it with throw, handle it in a try/catch block, and finally runs in every case. All exceptions implement Throwable; you catch the most specific type possible.

Example

try {
  $x = intdiv(1, 0);
} catch (DivisionByZeroError $e) {
  echo $e->getMessage();
}

Related concepts

The whole glossary