Replies: 4 comments 3 replies
-
I throw exceptions. The following are places where I throw exceptions:
So then I throw the exceptions from anywhere, but then I have a centralized exception handler. So I don't do catching in the use case by in the global exception handler. I use the global exception handler to convert the exceptions into whatever form is required by the presentation layer. |
Beta Was this translation helpful? Give feedback.
-
You can Indeed go all in with Exceptions as Valentina said. Another option is to use some kind of "Result" wrapper that wraps the response or the error. You'll have to handle it in the use case, without having to catch exception and thus inverse the flow of control. But is has downsides too, in language where there is no algebraic data type integrated it can be a bit verbose to just unwrap a value. |
Beta Was this translation helpful? Give feedback.
-
What about several specific exceptions handlers? Let's say you have a use case. It might throw 2 specific exceptions and each exception requires a specific flow management. Of course you could have a generic exception handler but that would mean handling a lot of possible exceptions in it. Would you say it's a good idea to handle your specific exceptions in dedicated handlers for that specific use case and in case you have unhandled exceptions you fallback on a generic exception handler? |
Beta Was this translation helpful? Give feedback.
-
@PCreations thanks for mentioning that. Yes, the two approaches boild down to:
@HunteRoi interesting remark. Do you have an example where each exception requires a specific flow management? If you have any sample repo on your GitHub, feel free to link here. I'm interested to see this situation, as I may consider it in expanding the Banking Kata... |
Beta Was this translation helpful? Give feedback.
-
Context: Imagine you want to read a file's properties from an API (because the file is stored in the cloud).
Use case: ReadFileProperties
Would you handle unhappy flows in your use case handler or outside of it?
Possible unhappy flows:
Happy flow (use case): you retrieve the properties of the file and return them to the caller
___
I have been poking around this topic for a little bit now, but I can't quite get to decide if I want to remove my unhappy flow management from the use case into a dedicated handler or not.
What's your opinion?
Beta Was this translation helpful? Give feedback.
All reactions