Esempio n. 1
0
 private static T HandleExceptions <T>(Func <T> func)
 {
     if (Active)
     {
         stopWatch.Reset();
         stopWatch.Start();
         try
         {
             return(func());
         }
         catch (VCException vcException)
         {
             VCExceptionHandler.HandleException(vcException);
         }
         catch (Exception e)
         {
             DebugLog.LogError("Unhandled exception: " + e.Message + "\n" + DebugLog.GetCallstack());
             throw;
         }
         finally
         {
             DebugLog.Log(new System.Diagnostics.StackTrace(1, true).GetFrames()[0].GetMethod().Name + " took " + stopWatch.ElapsedMilliseconds + "ms");
         }
     }
     else
     {
         DebugLog.Log("VC Action ignored due to not being active");
     }
     return(default(T));
 }
Esempio n. 2
0
        private T HandleExceptions <T>(Func <T> func, Action onException = null)
        {
            string callerMethod = new System.Diagnostics.StackTrace(1, true).GetFrames()?[0]?.GetMethod().Name ?? "UVC Operation (unknown)";

            using (ProfilerScope.Get(callerMethod))
            {
                if (Active)
                {
                    stopWatch.Reset();
                    stopWatch.Start();
                    try
                    {
                        return(func());
                    }
                    catch (VCException vcException)
                    {
                        VCExceptionHandler.HandleException(vcException);
                        onException?.Invoke();
                    }
                    catch (Exception e)
                    {
                        DebugLog.LogError("Unhandled exception: " + e.Message + "\n" + DebugLog.GetCallstack());
                        onException?.Invoke();
                        throw;
                    }
                    finally
                    {
                        DebugLog.Log(callerMethod + " took " + stopWatch.ElapsedMilliseconds + "ms");
                    }
                }
                else
                {
                    DebugLog.Log("VC Action ignored due to not being active");
                }
                return(default(T));
            }
        }