Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Handling exception #29

Answered by Mulkave
cgsauy asked this question in Q&A
Discussion options

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?

You must be logged in to vote

@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
  • If the exception had to be gracefully han...

Replies: 1 comment

Comment options

@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
  • 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

You must be logged in to vote
0 replies
Answer selected by Mulkave
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #28 on September 07, 2021 16:57.

AltStyle によって変換されたページ (->オリジナル) /