/// <summary>
        /// Handles all exceptions in the chain
        /// </summary>
        /// <param name="exceptionToHandle">The exception to handle</param>
        /// <returns>Whether or not a rethrow is recommended</returns>
        public bool Handle(Exception exceptionToHandle)
        {
            exceptionToHandle.NotNull(nameof(exceptionToHandle));

            return RethrowRecommended(
                ExecuteHandlerChain(exceptionToHandle, Guid.NewGuid()));
        }
Example #2
0
        /// <summary>
        /// Parameterized constructor.
        /// </summary>
        public MethodReturn(IMethodInvocation originalInvocation, Exception exception)
        {
            originalInvocation.NotNull("originalInvocation");
            exception.NotNull("exception");

            this.InvocationContext = originalInvocation.InvocationContext;
            this.Exception = exception;
            this.Outputs = new ParameterCollection(new object[0], new ParameterInfo[0], delegate { return false; });
        }
        /// <summary>
        /// Checks if there is a policy entry that matches
        /// the type of the specified exception,
        /// and if so, invokes the handlers associated with that entry
        /// </summary>
        /// <param name="exceptionToHandle">The exception to handle</param>
        /// <returns>True when rethrowing an exception is recommended</returns>
        public bool HandleException(Exception exceptionToHandle)
        {
            exceptionToHandle.NotNull(nameof(exceptionToHandle));

            var entry = GetPolicyEntry(exceptionToHandle);

            return entry.IsNull()
                ? true
                : entry.Handle(exceptionToHandle);
        }
Example #4
0
        /// <summary>
        /// Handles the specified exception object according to the rules configured for policyName
        /// </summary>
        /// <param name="exceptionToHandle">The exception to handle</param>
        /// <param name="policyName">The name of the policy to handle</param>        
        /// <returns>True if rethrowing an exception is recommended; otherwise, false</returns>
        /// <example>
        /// The following code shows the usage of the 
        /// exception handling framework.
        /// <code>
        ///    try
        ///    {
        ///        DoWork();
        ///    }
        ///    catch (Exception e)
        ///    {
        ///        if (exceptionManager.HandleException(e, name)) throw;
        ///    }
        /// </code>
        /// </example>
        public bool HandleException(
            Exception exceptionToHandle,
            string policyName = "default")
        {
            exceptionToHandle.NotNull(nameof(exceptionToHandle));
            policyName.NotNullOrEmpty(nameof(policyName));

            IExceptionPolicyDefinition exceptionPolicy;

            if (!_exceptionPolicies.TryGetValue(policyName, out exceptionPolicy))
                throw new InvalidOperationException("Exception policy not found");

            return exceptionPolicy.HandleException(exceptionToHandle);
        }
Example #5
0
        private static bool HandleException(
            Exception exceptionToHandle,
            string policyName = "default")
        {
            exceptionToHandle.NotNull(nameof(exceptionToHandle));
            policyName.NotNullOrEmpty(nameof(policyName));

            return ExceptionManager
                .HandleException(exceptionToHandle, policyName);
        }