c# - Repeating exception handling -
i have question repeating exception handling...
for example: webmethods have try-catch block , inside try block there execution code. try-catch blocks same each webmethod.
is there possibility make easier, more maintainable, without repeating same code? know aspects, there other solution?
the code lang c#, thing in general solution.
thanks answers.
using functional programming principles, can pass action or method want executed in way.
in c# can make method standardize code:
public void handleexceptions(action action) { try { action(); } catch (exceptiona exa) { } catch (exceptionb exb) { } { } } and call this:
handleexceptions(() => { //insert code handled try/catch structure method1(); }); handleexceptions(() => { method2(); });
Comments
Post a Comment