An exception is an event that occurs during the execution of a program that disrupts the normal flow of instructions. PHP uses exceptions to handle errors and other exceptional events.

If the handling of an exception implements both the catch and finally blocks, be advised that any finally block encountered in the way of the exception event will be executed, even when the event have already passed through the catch block.

Now that we understood the structure around exception events, let's see a couple of examples of how we can throw and catch exceptions.

Thereafter, if an exception gets thrown, the finally block will be triggered even if the exception event has been already handled by a catch block.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners