Exceptions are the mechanism to catch some invalid behavior and gracefully handle them instead of just showing "500 server error" to the users.
Take a look at this example:
public function __invoke(){ try { $this->import($data); } catch (ImportHasMalformedData $e) { return redirect()->route('dashboard')->with('message', 'Uh oh, the import has failed. Try again later or contact support'); } return 'Imported';}
This snippet means that in case of ANY Exception, the user would get redirected back and see the error message.
But what if we're expecting something specific to happen?
Catching a Specific Laravel Exception
Try-catch is way more helpful when catching a specific Exception. Laravel and 3rd party packages often offer...