You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment Laravel and Eloquent throw exceptions which are direct instances of PHP standard exceptions, i.e. mostly \InvalidArgument, \LogicException and so on.
When these exceptions propagate the call stack, it is difficult to specifically catch all exception which have been thrown by Laravel or Eloquent at a higher level of the stack. It would be really nice, if Laravel had its own root exception, an interface or both. For example, one could use an interface \Illuminate\Contracts\LaravalException and still use specific exceptions which extend the PHP standard exceptions if one would like, i.e. something like \Illuminate\Exceptions\InvalidArgument extends \invalidArgument implements \Illuminate\Contracts\LaravalException.
Using custom exception classes is also considered good practice.
As a work around, I usually implement my own, tailored exception like MyLaravelException and then wrap each and every single call of Laravel into an independent try-catch-clause in order to be able to properly track exceptions on higher levels of the stack. This means I write something like
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
At the moment Laravel and Eloquent throw exceptions which are direct instances of PHP standard exceptions, i.e. mostly
\InvalidArgument
,\LogicException
and so on.When these exceptions propagate the call stack, it is difficult to specifically catch all exception which have been thrown by Laravel or Eloquent at a higher level of the stack. It would be really nice, if Laravel had its own root exception, an interface or both. For example, one could use an interface
\Illuminate\Contracts\LaravalException
and still use specific exceptions which extend the PHP standard exceptions if one would like, i.e. something like\Illuminate\Exceptions\InvalidArgument extends \invalidArgument implements \Illuminate\Contracts\LaravalException
.Using custom exception classes is also considered good practice.
As a work around, I usually implement my own, tailored exception like
MyLaravelException
and then wrap each and every single call of Laravel into an independent try-catch-clause in order to be able to properly track exceptions on higher levels of the stack. This means I write something likeThis is extremely tedious and make my code clumsy.
Beta Was this translation helpful? Give feedback.
All reactions