Beispiel #1
0
        private TestCatch GetCorrectCatchForException(Type type)
        {
            TestCatch solution = null;

            // what this does it it loops through the catches until it finds an assignable type. (IE a child or match)
            //  To make sure we get the most specific match, it loops through again using the type of the matching catch
            foreach (TestCatch testcatch in _catches)
            {
                if (testcatch.ExceptionType.IsAssignableFrom(type))
                {
                    if (solution == null)
                    {
                        solution = testcatch;
                        break;
                    }
                    else
                    {
                        if (testcatch.ExceptionType.IsAssignableFrom(solution.ExceptionType))
                        {
                            solution = testcatch;
                            break;
                        }
                    }
                }
            }
            return(solution);
        }
Beispiel #2
0
        protected override void GetActivitySpecificTrace(TraceGroup traceGroup)
        {
            // This lets the old Hint still work
            foreach (TestCatch testCatch in this.Catches)
            {
                if (testCatch.HintHandleException)
                {
                    if (!TracingHelper.CatchAnException(testCatch.ExceptionType, Try))
                    {
                        //Log.TraceInternal("Warning- Catch marked as handle, isnt handling exception.");
                    }
                    break;
                }
            }

            if (this.Try != null)
            {
                Outcome tryOutcome = Try.GetTrace(traceGroup);

                CaughtExceptionOutcome ceo = tryOutcome as CaughtExceptionOutcome;

                // if state is catching exception
                if (ceo != null)
                {
                    // look for a catch to handle this exception
                    TestCatch testcatch = GetCorrectCatchForException(ceo.ExceptionType);

                    if (testcatch == null)
                    {
                        CurrentOutcome = tryOutcome;
                    }
                    else
                    {
                        // wipe out the CaughtExceptionOutcome in case no body is set
                        CurrentOutcome = Outcome.Completed;

                        if (testcatch.Body != null)
                        {
                            // our return state is the catches return state
                            CurrentOutcome = testcatch.Body.GetTrace(traceGroup);
                        }
                    }
                }
                else
                {
                    CurrentOutcome = tryOutcome;
                }
            }

            if (!(CurrentOutcome is UncaughtExceptionOutcome) && Finally != null)
            {
                Outcome finallyOutcome = this.Finally.GetTrace(traceGroup);
                if (finallyOutcome.DefaultPropogationState != OutcomeState.Completed)
                {
                    CurrentOutcome = finallyOutcome;
                }
            }
        }
Beispiel #3
0
 protected void AddCatch(TestCatch item)
 {
     this.ProductTryCatchFinally.Catches.Add(item.NonGenericProductCatch);
 }
Beispiel #4
0
 protected void InsertCatch(int index, TestCatch item)
 {
     this.ProductTryCatchFinally.Catches.Insert(index, item.NonGenericProductCatch);
 }