public static void DisposeExceptionManager(this IAsyncBuilder builder) { if (builder.HasExceptionManager()) { builder.ExceptionManager.Dispose(); } }
/// <summary> /// Triggers the logic associated to a catch block on synchronic code. Looks for a suitable excpetion through the same family /// </summary> /// <typeparam name="T">The type of the exception</typeparam> /// <param name="ex">The instance of the exception</param> /// <param name="builder">The instance of the parent builder</param> private void HandleException <T>(T ex, IAsyncBuilder builder) where T : Exception { if (builder != null && builder.HasExceptionManager()) { var exceptionManager = builder.ExceptionManager as ExceptionManager; Delegate genericException = null; Delegate specificException = null; exceptionManager.Exceptions.TryGetValue(TYPE_OF_EXCEPTION, out genericException); //If System.Exception no need to look for a more specific exception. if (typeof(T) != TYPE_OF_EXCEPTION) { exceptionManager.Exceptions.TryGetValue(typeof(T), out specificException); if (specificException != null) { //The type of the thrown exception is different than System.Exception and has catch that handles it specifically. (specificException as Action <T>)(ex); return; } } if (genericException != null) { //If no specific excption is declared then the generic catch handles it. (genericException as Action <T>)(ex); return; } else if (builder == null) { //If no more parents the exception must be handled asynchronically. return; } else { //Look for another exception in the chain HandleException <T>(ex, builder.Parent); } } }