c# 4.0 - C# way to write Func with void return -


i have following 2 functions, identical, difference 1 uses func, other action. , i'd combine them 1 function if possible.

    private static void trycatch(action action)     {         try         {             action();         }         catch (exception x)         {             emailer.logerror(x);             throw;         }     }      private static tresult trycatch<tresult>(func<tresult> func)     {         try         {             return func();         }         catch (exception x)         {             emailer.logerror(x);             throw;         }     } 

combining these 2 1 function in c# isn't possible. void in c#, , clr, isn't type , hence has different return semantics non-void function. way implement such pattern provide overload void , non-void delegates

the clr limitation doesn't mean it's impossible in every clr language. it's impossible in languages use void represent function returns no values. pattern doable in f# because uses unit instead of void methods fail return value.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -