Laravel: Is it possible to log stack trace when exception caught, and continue the execution?
You can simply call your app's exception handler manually:
<?php
use App\Exceptions\Handler;
try {
foo();
} catch(\Exception $e) {
$h = new Handler(app());
$h->report($e);
}
bar();
This gives you the same error reporting you'd normally get, including any customizations you may have made for additional logging channels, etc.
Laravel has a helper method just for this, see the rescue method.
return rescue(function () {
return $this->method();
});
Using your example it would look like:
rescue(function () {
return foo();
});
bar();