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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners