Amazon.S3.Transfer.Internal.DownloadCommand.HandleException C# (CSharp) Method

HandleException() private static method

private static HandleException ( Exception exception, int retries, int maxRetries ) : bool
exception System.Exception
retries int
maxRetries int
return bool
        private static bool HandleException(Exception exception, int retries, int maxRetries)
        {
            var canRetry = true;
            if (exception is IOException)
            {
#if !PCL && !CORECLR
                while (exception.InnerException != null)
                {
                    if (exception.InnerException is ThreadAbortException)
                    {
                        Logger.Error(exception, "Encountered a IOException caused by a ThreadAbortException.");
                        return false;
                    }
                    exception = exception.InnerException;
                }
#endif
                if (retries < maxRetries)
                {
                    Logger.InfoFormat("Encountered an IOException. Retrying, retry {0} of {1}.",
                        retries, maxRetries);
                    return true;
                }
                else
                    canRetry = false;
            }

#if !CORECLR
            var webException = exception as WebException;
            if (webException != null)
            {
                Logger.Error(exception, "Encountered a WebException ({1}).", webException.GetType().Name, webException.Status);
                if (WebExceptionStatusesToRetryOn.Contains(webException.Status) && retries < maxRetries)
                {

                    Logger.InfoFormat("Encountered a WebException ({0}). Retrying, retry {1} of {2}.",
                        webException.Status, retries, maxRetries);
                    return true;
                }
                else
                    canRetry = false;
            }
#endif
            if (!canRetry)
            {
                Logger.Error(exception, "Encountered a {0}. Reached maximum retries {1} of {2}.", exception.GetType().Name, retries, maxRetries);
                return false;
            }

            Logger.Error(exception, "Encountered a non retryable {0}, rethrowing exception.", exception.GetType().Name);
            return false;
        }