using System; namespace ICD.Common.Utils { public static class TryUtils { /// /// /// /// return type /// /// /// public static bool Try(Func function, out TResult val) { if (function == null) throw new ArgumentNullException("function"); try { val = function(); return true; } catch (Exception) { val = default(TResult); return false; } } public static bool Try(Func function, T1 param1, out TResult val) { if (function == null) throw new ArgumentNullException("function"); return Try(() => function(param1), out val); } public static bool Try(Func function, T1 param1, T2 param2, out TResult val) { if (function == null) throw new ArgumentNullException("function"); return Try(() => function(param1, param2), out val); } public static bool Try(Func function, T1 param1, T2 param2, T3 param3, out TResult val) { if (function == null) throw new ArgumentNullException("function"); return Try(() => function(param1, param2, param3), out val); } } }