First off, I present you the context. I am writing an api in C# and ASP.NET Core and I am trying to follow the clean architecture.
In summary : I don't know where to put my exceptions. I have written a little scenario where I explain my logic.
- Suppose that I throw a DuplicatePersonException in a concrete gateway.
- This exception will be caught by my use case (interactor) as a simple exception. I don't think that the use case has to know the real exception.
- When I catch the error, I will call a method in my OutputBoundary (presenter).
- In the end, this presenter will format the answer and prepare an adequate ActionResult based on DuplicatePersonException.
If I respect the « inward dependency », I have to put my DuplicatePersonException in my use case layer. Why not in the domain layer ? Because it does not have to know this kind of exception. What's more, I don't know if I have to create an abstract custom exception and extends it both in the gateway layer and in the presenter layer : it makes me a little bit confused.
In fine, this solution doesn’t sound good to me but I am not able to explain why. It does not feel right to put my exceptions in this layer.
In conclusion, if you have any advice or solution, I will accept them with great pleasure !
Thank you very much for trying to help me !