Effective error handling and logging are essential parts of an application. Early versions of PHP lacked the support for exceptions and only used errors to flag faulty application states. The PHP 5 version brought forth the OOP features to the language and, with it, the exception model. This empowered PHP with the try...catch
blocks like other programming languages. Later, the PHP 5.5 version brought support for the finally
block, which always executed after the try...catch
blocks, regardless of whether an exception was thrown or not.
Nowadays, the PHP language differentiates errors and exceptions as faulty states of an application. Both are raised as unexpected to our application logic. There are numerous types of errors, such as E_ERROR
, E_WARNING
, E_NOTICE
, and others. When speaking of errors, we default to the E_ERROR
type that tends to signal the end of our application, an unexpected state that an application should not try to catch and continue...