예제 #1
0
 public void Dispose()
 {
     while (actions.Count > 0)
     {
         Catcher.Try(actions.Pop());
     }
 }
예제 #2
0
 public void StaticIgnoreTest()
 {
     Catcher.Try(
         () =>
     {
         throw new Exception("Error on Action!");
     }
         );
 }
예제 #3
0
        public void InstanceIgnoreTest()
        {
            var catcher = new Catcher();

            catcher.Run(
                () =>
            {
                throw new Exception("Error on Action!");
            }
                );
        }
예제 #4
0
        public void StaticHandleTest()
        {
            var exceptions = new List <Exception>();

            Catcher.Try(
                () =>
            {
                throw new Exception("Error on Action!");
            },
                (ex) =>
            {
                exceptions.Add(ex);
                throw new Exception("Error on Handler!");
            }
                );

            Assert.AreEqual(1, exceptions.Count);
            Assert.AreEqual("Error on Action!", exceptions[0].Message);
        }
예제 #5
0
        private void Loop()
        {
            while (!disposed)
            {
                if (idle == null)
                {
                    var action = idle;

                    lock (queue)
                    {
                        if (queue.Count == 0)
                        {
                            Monitor.Wait(queue);
                        }
                        if (queue.Count > 0)
                        {
                            action = queue.Dequeue();
                        }
                    }

                    if (action != null)
                    {
                        Catcher.Try(action, catcher);
                    }
                }
                else
                {
                    var action = idle;

                    lock (queue)
                    {
                        if (queue.Count > 0)
                        {
                            action = queue.Dequeue();
                        }
                    }

                    Catcher.Try(action, catcher);
                }
            }
        }
예제 #6
0
        public void Log(Log log)
        {
            formatter.Format(log);

            runner.Run(() =>
            {
                foreach (var appender in appenders)
                {
                    Catcher.Try(() => appender(log), (ex) =>
                    {
                        removes.Add(appender);
                        Thrower.Dump(ex);
                    });
                }
                //autoremove excepting appenders
                foreach (var appender in removes)
                {
                    appenders.Remove(appender);
                }
                removes.Clear();
            });
        }
예제 #7
0
        public void InstanceHandleTest()
        {
            var exceptions = new List <Exception>();

            var catcher = new Catcher(
                (ex) =>
            {
                exceptions.Add(ex);
                throw new Exception("Error on Handler!");
            }
                );

            catcher.Run(
                () =>
            {
                throw new Exception("Error on Action!");
            }
                );

            Assert.AreEqual(1, exceptions.Count);
            Assert.AreEqual("Error on Action!", exceptions[0].Message);
        }
예제 #8
0
 public ControlRunner(Control control, Action <Exception> catcher = null)
 {
     this.control = control;
     this.catcher = new Catcher(catcher);
 }
예제 #9
0
 public static void Dispose(IDisposable disposable)
 {
     Catcher.Try(() => { disposable?.Dispose(); });
 }