As I mentioned above - javascript pipelines (named `Promise` and
`Thenable`) are great examples when exceptions are a bad choice. Btw, not
"bad", but "choice to stop one step of the chain only".

If any step of chain/foreach throws an exception - it will break all code.
Should break one step. That's why you throw the immediate catch. And
continue to check via if-checking once the result of the pipeline is
received.

Catching is a good solution for the application core. If some exception
pops up at the entrypoint - you could transform the exception to the
output. All other cases should be covered without exceptions. If you use
exceptions on any occurred error as "truth way" you will meet risk and also
timeloss on any misformatted batches/user-inputs.

ср, 7 февр. 2024 г. в 18:06, Григорий Senior PHP / Разработчик Web <
6562...@gmail.com>:

> Analyzing the problem on a single level operation is incorrect. New code
> and simple operations are fully covered with exception/try/catch flow.
>
> The main point i tried to attract your attention is that if you working in
> batches/queues/pipelines you still need errors collection, and if you made
> error flow with exceptions - you have to extract validations to separate
> classes/dto-s, made return types as objects, try/catching as fast as
> possible, and then you will still met errors from remote systems, network
> errors, and invalid response parsing that need to be logged as much close
> to task registration place.
>
> So correct analysis - providing an example with at least foreaches/yields
> instead of simply calling native functions. In small functions IF
> statements are overkill, and even try-catch could be skipped, because the
> whole script will fall and that's correct behavior.
>
> Case is in that the script should continue working while working with
> chaining/nesting, and should be able to easily refactor any step to skip
> one or more bulk-data rows of each step on any nesting level.
>


-- 
+375 (29) 676-48-68 <+375296764868> / Mobile - предпочитаемый способ связи
https://t.me/gzhegow / https://t.me/%2B375296764868 / Telegram
6562...@gmail.com

Reply via email to