-
-
Notifications
You must be signed in to change notification settings - Fork 58
-
Hello, what do you recommend for handling exceptions in function or operation?
I think I should launch it at Job and capture in the Features, Operation Or Controller, but I don't know if it is recommended.
Can you give me a suggestion?
Beta Was this translation helpful? Give feedback.
All reactions
@cgsauy The best way to handle exceptions is the Laravel native way, as long as we're talking about HTTP exceptions that can be thrown at any level in the app and then their handling centralised at the exception handler app/Exceptions/Handler.php. This is best because it is the most anticipated place for us to find them, and that way handling doesn't get lost in the nesting of the logic.
However, if you were to handle certain exceptions to do something upon their occurrence (try/catch) you may then decide depending on the responsibility of the handler. For example if you had the following structure:
-
Feature
- Operation
- Job: throws exception
- Operation
-
If the exception had to be gracefully han...
Replies: 1 comment
-
@cgsauy The best way to handle exceptions is the Laravel native way, as long as we're talking about HTTP exceptions that can be thrown at any level in the app and then their handling centralised at the exception handler app/Exceptions/Handler.php. This is best because it is the most anticipated place for us to find them, and that way handling doesn't get lost in the nesting of the logic.
However, if you were to handle certain exceptions to do something upon their occurrence (try/catch) you may then decide depending on the responsibility of the handler. For example if you had the following structure:
-
Feature
- Operation
- Job: throws exception
- Operation
-
If the exception had to be gracefully handled and the operation to continue, you'd handle it at the Operation level
-
If the exception demands that the operation halts but the feature continues, then you'd handle it at the Feature level
-
If the exception means that the request should stop just there, then the handling should be at the HTTP exceptions handler
app/Exceptions/Handler.php -
If the exception requires no handling at all, nor is it alarming and may just require a simple log event that doesn't concern the upper units, the Job that caused the exception could handle it silently and all the above goes about their day
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2