https://dev.to/clintwinter https://laravel.com/docs/9.x/helpers#method-rescue is an alternative to the traditional try/catch block syntax required when you want to manually handle a thrown exception. The result of the callback will be returned if no exception is thrown.

$country = 'USA'; try { $alpha2 = (new ISO3166)->alpha3($country)['alpha2']; } catch (\Exception $e) { $alpha2 = null; }

That's where rescue's second parameter comes in: $isFalse = rescue(function () { throw new Exception; }, false); Exit fullscreen mode

rescue(function () { throw new Exception; }, function ($e) { // do exception related stuff return false; }); // => false
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