IMHO some of the patterns published here are breaking the Single responsibility principle Exception classes should contain any exception-related methods, with some properties to store additional information (e.g. reference to the execution context, like a DB statement). The "check" methods should not be part of the exception, but to the corresponding process, perhaps in another class. You can then "inject" the exception class to the "check class" (with a parameter of type EMyExceptionClass = class of EMyException), so that you got the best of both worlds.
Yes, it's a good approach for predicates. :)
ReplyDeleteA good method, it improves the cleanness of the code, thanks!
ReplyDeleteIMHO some of the patterns published here are breaking the Single responsibility principle
ReplyDeleteException classes should contain any exception-related methods, with some properties to store additional information (e.g. reference to the execution context, like a DB statement).
The "check" methods should not be part of the exception, but to the corresponding process, perhaps in another class. You can then "inject" the exception class to the "check class" (with a parameter of type EMyExceptionClass = class of EMyException), so that you got the best of both worlds.