0

I have some data access methods and was wondering if there was a way to implement a error handling function that would take these data access methods as a parameter and execute them inside the try/catch of this generic static error handling function that would just log and throw the error if the method it was executing throws an exception.

Is there a pattern for this to reduce code duplication for error handling if the way that they are handled in the catch are going to be the same?

  • 1
    Yes, there is a pattern for that, AOP (Aspect Oriented Programming). [PostSharp](http://doc.postsharp.net/exception-handling) is a well known one (but not free) but there are others for .Net. If you want to do it manually take a look at [this Q&A](https://stackoverflow.com/questions/40277320/how-can-i-use-simple-aspect-oriented-concept-to-handle-exception-handling-without) – Peter Bons May 18 '18 at 20:43
  • anyway to use function pointers or I guess delegates to do the same thing? – ProgrammerAdept May 19 '18 at 00:46

0 Answers0