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

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -