How can I avoid duplicated try catch blocks

后端 未结 4 1061
我在风中等你
我在风中等你 2021-02-08 06:18

I have several methods that look like this:

public void foo()
{
   try 
   {
      doSomething();
   }
   catch(Exception e)
   {
      Log.Error(e);
   }
 }
         


        
4条回答
  •  隐瞒了意图╮
    2021-02-08 06:56

    Since you mentioned you're using WCF you can implement IErrorHandler interface and all exceptions would be routed to your method where you can log them.

    • http://www.extremeexperts.com/Net/Articles/ExceptionHandlingInWCF.aspx
    • http://codeifollow.blogspot.com/2010/02/wcf-exception-handling.html

提交回复
热议问题