internal static void ValidateAndTrace(int fserr, PtsContext ptsContext) { if (fserr != fserrNone) { ErrorTrace(fserr, ptsContext); } }
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)); } }
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; } }
private static Exception GetInnermostException(PtsContext ptsContext) { Invariant.Assert(ptsContext != null); Exception exception = ptsContext.CallbackException; Exception innerException = exception; while (innerException != null) { innerException = exception.InnerException; if (innerException != null) { exception = innerException; } if (!(exception is PtsException || exception is SecondaryException)) { break; } } return exception; }
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; } }