Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public static bool TryClone(Exception exception, out Exception clone)
        {
            if (exception == null)
            {
                throw new ArgumentNullException("exception");
            }
            clone = null;
            IRethrowableException rethrowableException = exception as IRethrowableException;

            if (rethrowableException == null)
            {
                return(false);
            }
            clone = rethrowableException.GetRethrowableClone();
            return(true);
        }