Prefer Throwing Custom Exceptions For Cleaner Code #shorts

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

My project is doing this. Defined custom exceptions and globally handled it, making it way easier to explain what that code is doing.

ezarp
Автор

Prefer don't throw exceptions at all and use Monads ❤

yohm
Автор

It is easier to debug that is the first thing to do exception
UserNotFoundException
ProductNotFoundException
easier to debug
NotFoundException

mzerone-gm
Автор

Generally throwing the exceptions in a business logic is a bad idea and I see two reasons for that:
1. Exceptions are quite expensive from the performance point of view;
2. Exceptional situation is when you can not control something, for instance lost connection to the db or message broker, etc.
When you want to throw an exception in a business logic it most likely looks like one of many possible scenarios of the logic and in such case it can not be treated as an exception - it's an error.
How to work with errors? - You should take a look into the "Reault type" pattern

OleksandrAndreiev