System.Net.WebException.CreateCompatibleException C# (CSharp) Method

CreateCompatibleException() static private method

static private CreateCompatibleException ( Exception exception ) : Exception
exception Exception
return Exception
        internal static Exception CreateCompatibleException(Exception exception)
        {
            Debug.Assert(exception != null);
            if (exception is HttpRequestException)
            {
                Exception inner = exception.InnerException;
                string message = inner != null ?
                    string.Format("{0} {1}", exception.Message, inner.Message) :
                    exception.Message;

                return new WebException(
                    message,
                    exception,
                    GetStatusFromException(exception as HttpRequestException),
                    null);
            }

            return exception;
        }
    }

Usage Example

示例#1
0
        public override WebResponse EndGetResponse(IAsyncResult asyncResult)
        {
            CheckAbort();

            if (asyncResult == null || !(asyncResult is Task <WebResponse>))
            {
                throw new ArgumentException(SR.net_io_invalidasyncresult, nameof(asyncResult));
            }

            if (Interlocked.Exchange(ref _endGetResponseCalled, 1) != 0)
            {
                throw new InvalidOperationException(SR.Format(SR.net_io_invalidendcall, "EndGetResponse"));
            }

            WebResponse response;

            try
            {
                response = ((Task <WebResponse>)asyncResult).GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                throw WebException.CreateCompatibleException(ex);
            }

            return(response);
        }
All Usage Examples Of System.Net.WebException::CreateCompatibleException