Beispiel #1
0
        public virtual O Execute <T, I, O>(I args) where T : AbstractCallable, ICallable
        {
            StackTraceCollector stackTraceCollector = new StackTraceCollector(this);
            var op = Get <ICallable, T>();

            try
            {
                var result = op.Apply <O>(args);
                this.CallStack = null;
                return(result);
            }
            catch (Exception e) // Dumps q# call-stack in case of exception if CallStack tracking was enabled
            {
                this.CallStack = stackTraceCollector.CallStack;
                OnLog?.Invoke($"Unhandled exception. {e.GetType().FullName}: {e.Message}");
                bool first = true;
                foreach (StackFrame sf in this.CallStack)
                {
                    var msg = (first ? " ---> " : "   at ") + sf.ToStringWithBestSourceLocation();
                    OnLog?.Invoke(msg);
                    first = false;
                }
                OnLog?.Invoke("");

                throw;
            }
            finally
            {
                stackTraceCollector.Dispose();
            }
        }
        public virtual O Execute <T, I, O>(I args) where T : AbstractCallable, ICallable
        {
            StackTraceCollector stackTraceCollector = new StackTraceCollector(this);
            var op = Get <ICallable, T>();

            try
            {
                var result = op.Apply <O>(args);
                this.CallStack = null;
                return(result);
            }
            catch (Exception e) // Dumps q# call-stack in case of exception if CallStack tracking was enabled
            {
                this.CallStack = stackTraceCollector.CallStack;
                this.OnException?.Invoke(e, this.CallStack);
                throw;
            }
            finally
            {
                stackTraceCollector.Dispose();
            }
        }