Example #1
0
        public static Exception AttemptClone(Exception ex, RethrowableWrapperBehavior behavior)
        {
            LateBoundMethod lateBoundMethod;
            Exception       rethrowableClone = null;

            if (ex == null)
            {
                return(null);
            }
            IRethrowableException rethrowableException = ex as IRethrowableException;

            if (rethrowableException != null)
            {
                rethrowableClone = rethrowableException.GetRethrowableClone();
            }
            else if (ExceptionCloner.exceptionTypesWhichCanBeCloned.TryGetValue(ex.GetType(), out lateBoundMethod))
            {
                object[] objArray = new object[] { ex };
                rethrowableClone = (Exception)lateBoundMethod(null, objArray);
            }
            else if (behavior != RethrowableWrapperBehavior.NoWrap)
            {
                rethrowableClone = RethrowableWrapperException.MakeRethrowable(ex);
            }
            else
            {
                ExceptionCloner.remoteStackTraceSetter(ex, ex.StackTrace);
                rethrowableClone = ex;
            }
            return(rethrowableClone);
        }
Example #2
0
 public void End(out Exception exceptionToThrow, RethrowableWrapperBehavior wrapperBehavior)
 {
     if (AsyncResultBase.completeWaitHandleSentinel != this.waitHandle)
     {
         this.AsyncWaitHandle.WaitOne();
         this.waitHandle.Close();
         this.waitHandle = null;
     }
     exceptionToThrow = null;
     try
     {
         exceptionToThrow = ExceptionCloner.AttemptClone(this.exception, wrapperBehavior);
     }
     catch (TypeInitializationException typeInitializationException)
     {
     }
     this.exception = null;
 }
Example #3
0
        private static void End(this IAsyncResult asyncResult, RethrowableWrapperBehavior wrapperBehavior = 0)
        {
            Exception exception;

            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }
            AsyncIteratorContext asyncIteratorContext = asyncResult as AsyncIteratorContext;

            if (asyncIteratorContext == null)
            {
                throw new InvalidOperationException(string.Format("End may only be called on result of type '{0}', given type is '{1}'", typeof(AsyncIteratorContext), asyncResult.GetType()));
            }
            asyncIteratorContext.End(out exception, wrapperBehavior);
            if (exception != null)
            {
                throw exception;
            }
        }
Example #4
0
        public static TResultData End <TResultData>(this IAsyncResult asyncResult, RethrowableWrapperBehavior wrapperBehavior = 0)
        {
            Exception exception;

            if (asyncResult == null)
            {
                throw new ArgumentNullException("asyncResult");
            }
            AsyncIteratorContext <TResultData> asyncIteratorContext = (AsyncIteratorContext <TResultData>)asyncResult;

            if (asyncIteratorContext == null)
            {
                throw new InvalidOperationException(string.Format("End may only be called on result of type '{0}', given type is '{1}'", typeof(AsyncIteratorContext <TResultData>), asyncResult.GetType()));
            }
            asyncIteratorContext.End(out exception, wrapperBehavior);
            if (exception != null)
            {
                throw exception;
            }
            return(asyncIteratorContext.ResultData);
        }