Beispiel #1
0
        internal static void UninstallExceptionHandler <T>(
            IExceptionHandler <T> handler) where T : Exception
        {
            var exType = typeof(T);

            lock (ExceptionHandlers)
            {
                if (!ExceptionHandlers.TryGetValue(exType, out var collection))
                {
                    return;
                }

                collection.RemoveAll(o => o.Item1 == handler);
                ExceptionHandlers[exType] = collection;
                ExceptionHandlerCache.TryRemove(exType, out _);
            }
        }
Beispiel #2
0
        internal static void InstallExceptionHandler <T>(
            IExceptionHandler <T> handler) where T : Exception
        {
            var exType = typeof(T);

            lock (ExceptionHandlers)
            {
                if (!ExceptionHandlers.TryGetValue(exType, out _))
                {
                    ExceptionHandlers[exType] =
                        new List <Tuple <IExceptionHandler, Func <Operation, Exception, ExceptionHandlingStrategy> > >();
                }

                ExceptionHandlers[exType].Add(
                    Tuple.Create <IExceptionHandler, Func <Operation, Exception, ExceptionHandlingStrategy> >(
                        handler,
                        (op, ex) => handler.Handle(op, ex as T)
                        )
                    );
                ExceptionHandlerCache.TryRemove(exType, out _);
            }
        }