Exemplo n.º 1
0
        /// <summary>
        /// Checks if there is a policy entry that matches
        /// the type of the exception object specified by the
        /// <see cref="Exception"/> parameter
        /// and if so, invokes the handlers associated with that entry.
        /// </summary>
        /// <param name="ex">The <c>Exception</c> to handle.</param>
        /// <returns>Whether or not a rethrow is recommended.</returns>
        /// <remarks>
        /// The algorithm for matching the exception object to a
        /// set of handlers mimics that of a standard .NET exception policy.
        /// The specified exception object will be matched to a single
        /// exception policy entry by traversing its inheritance hierarchy.
        /// This means that if a <c>FileNotFoundException</c>, for example, is
        /// caught, but the only exception type that the exception policy
        /// knows how to handle is System.Exception, the event handlers
        /// for <c>System.Exception</c> will be invoked because
        /// <c>FileNotFoundException</c> ultimately derives from <c>System.Exception</c>.
        /// </remarks>
        private bool HandleException(Exception ex)
        {
            Type exceptionType         = ex.GetType();
            ExceptionPolicyEntry entry = this.FindExceptionPolicyEntry(exceptionType);

            bool recommendRethrow = false;

            if (entry == null)
            {
                // If there is no Entry for this type / policy than we recommend a rethrow.
                recommendRethrow = true;
                ExceptionNotHandledEvent.Fire();
            }
            else
            {
                try
                {
                    recommendRethrow = entry.Handle(ex);
                    ExceptionHandledEvent.Fire();
                }
                catch (ExceptionHandlingException)
                {
                    ExceptionNotHandledEvent.Fire();
                    throw;
                }
            }
            return(recommendRethrow);
        }
Exemplo n.º 2
0
 /// <devdoc>
 /// Rethrows the given exception.  Placed in a seperate method for
 /// easier viewing in the stack trace.
 /// </devdoc>
 private void IntentionalRethrow(Exception chainException, Exception originalException)
 {
     if (chainException != null)
     {
         ExceptionHandledEvent.Fire();
         throw chainException;
     }
     else
     {
         Exception wrappedException = new ExceptionHandlingException(SR.ExceptionNullException);
         ExceptionUtility.LogHandlingException(policyName, wrappedException, chainException, originalException);
         throw wrappedException;
     }
 }
 private void FireExceptionHandledEvent()
 {
     ExceptionHandledEvent.Fire();
 }