What should i use Exceptions or Monads for handle if service occur a problem?

26 Views Asked by At

I have controller and service with it. I call service method and if error occur inside what should i do? First, I just throw exception and handle them in exception middleware. Second, I write a custom Either monad, and if exception should be, I return Either.Error(Object that contains error info). Or if all work correct, I return Either.Success(Value). Third, I write a abstract class Service, and all services must inherit from it. In that class I declare some static methods that return one info object(like IActionResult in controllers). And after it same scheme like in second variant. What's best practice? Maybe my options are bad at all.

Each of the options presented has cons and pros for me, but which is better in your opinion? Maybe you have another solution?

0

There are 0 best solutions below