Пример #1
0
        private static void Error(int fserr, PtsContext ptsContext)
        {
            switch (fserr)
            {
                case fserrOutOfMemory:
                    throw new OutOfMemoryException();

                case fserrCallbackException:
                    Debug.Assert(ptsContext != null, "Null argument 'ptsContext' - required for return value validation.");
                    if (ptsContext != null)
                    {
                        SecondaryException se = new SecondaryException(ptsContext.CallbackException);
                        ptsContext.CallbackException = null;
                        throw se;
                    }
                    else
                    {
                        throw new Exception(SR.Get(SRID.PTSError, fserr));
                    }

                case tserrPageTooLong:
                case tserrSystemRestrictionsExceeded:
                    throw new PtsException(SR.Get(SRID.FormatRestrictionsExceeded, fserr));

                default:
                    throw new PtsException(SR.Get(SRID.PTSError, fserr));
            }
        }
Пример #2
0
        public async Task FallbackFailsIfPrimaryAndSecondaryThrow()
        {
            var       exception1 = new Exception();
            var       exception2 = new SecondaryException();
            Try <int> result     = await Fallback.ExecuteAsync <int>(
                () => throw exception1,
                () => throw exception2);

            Assert.False(result.Success);
            Assert.IsType <AggregateException>(result.Exception);
            var aggregateException = result.Exception as AggregateException;

            Assert.NotNull(aggregateException);
            Assert.NotNull(aggregateException.InnerExceptions);
            Assert.Equal(2, aggregateException.InnerExceptions.Count);
            Assert.True(aggregateException.InnerExceptions.Contains(exception1));
            Assert.True(aggregateException.InnerExceptions.Contains(exception2));
        }
Пример #3
0
        private static void ErrorTrace(int fserr, PtsContext ptsContext)
        {
            switch (fserr)
            {
                case fserrOutOfMemory:
                    throw new OutOfMemoryException();

                default:
                    Debug.Assert(ptsContext != null, "Null argument 'ptsContext' - required for return value validation."); 
                    if (ptsContext != null)
                    {
                        Exception innerException = GetInnermostException(ptsContext);
                        if (innerException == null || innerException is SecondaryException || innerException is PtsException)
                        {


                            string message = (innerException == null) ? String.Empty : innerException.Message;
                            if (TracePageFormatting.IsEnabled)
                            {
                                TracePageFormatting.Trace(
                                    TraceEventType.Start,
                                    TracePageFormatting.PageFormattingError,
                                    ptsContext,
                                    message);
                                TracePageFormatting.Trace(
                                    TraceEventType.Stop,
                                    TracePageFormatting.PageFormattingError,
                                    ptsContext,
                                    message);
                            }
                        }
                        else
                        {

                            SecondaryException se = new SecondaryException(innerException);
                            ptsContext.CallbackException = null;
                            throw se;
                        }
                    }
                    else
                    {
                        throw new Exception(SR.Get(SRID.PTSError, fserr));
                    }
                    break;
            }
        }
Пример #4
0
        private static void ErrorTrace(int fserr, PtsContext ptsContext)
        {
            switch (fserr)
            {
                case fserrOutOfMemory:
                    throw new OutOfMemoryException();

                default:
                    Debug.Assert(ptsContext != null, "Null argument 'ptsContext' - required for return value validation."); 
                    if (ptsContext != null)
                    {
                        Exception innerException = GetInnermostException(ptsContext);
                        if (innerException == null || innerException is SecondaryException || innerException is PtsException)
                        {
                            // The only exceptions thrown were our own for PTS errors. We shouldn't throw in this case but should
                            // log the error if debug tracing is enabled
                            string message = (innerException == null) ? String.Empty : innerException.Message;
                            if (TracePageFormatting.IsEnabled)
                            {
                                TracePageFormatting.Trace(
                                    TraceEventType.Start,
                                    TracePageFormatting.PageFormattingError,
                                    ptsContext,
                                    message);
                                TracePageFormatting.Trace(
                                    TraceEventType.Stop,
                                    TracePageFormatting.PageFormattingError,
                                    ptsContext,
                                    message);
                            }
                        }
                        else
                        {
                            // There's an actual third-party exception that we didn't create. Throw it.
                            SecondaryException se = new SecondaryException(innerException);
                            ptsContext.CallbackException = null;
                            throw se;
                        }
                    }
                    else
                    {
                        throw new Exception(SR.Get(SRID.PTSError, fserr));
                    }
                    break;
            }
        }