Table of Contents

Class WebException

Namespace
System.Net
Assembly
System.Net.Http.dll

Defines the exception that is thrown by WebRequest instances when an error occurs.

public class WebException : InvalidOperationException
Inheritance
WebException
Inherited Members
Extension Methods

Remarks

This class is a subclass of InvalidOperationException that contains a WebExceptionStatus and possibly a reference to a WebResponse. The WebResponse is only present if there is a response from the remote server.

Constructors

WebException()

The default constructor.

public WebException()

WebException(string)

Constructs a WebException based on the specified message string.

public WebException(string message)

Parameters

message string

The message string for the exception.

WebException(string, Exception)

Constructs a WebException based on the specified message string and inner exception.

public WebException(string message, Exception innerException)

Parameters

message string

The message string for the exception.

innerException Exception

The exception that caused this exception.

WebException(string, Exception, WebExceptionStatus, WebResponse)

Constructs a WebException based on the specified message string, inner exception, WebExceptionStatus, and WebResponse.

public WebException(string message, Exception inner, WebExceptionStatus status, WebResponse response)

Parameters

message string

Message string for exception.

inner Exception

The exception that caused this exception.

status WebExceptionStatus

The network status of the exception.

response WebResponse

The WebResponse we have.

WebException(string, WebExceptionStatus)

Constructs a WebException based on the specified message string and WebExceptionStatus.

public WebException(string message, WebExceptionStatus status)

Parameters

message string

The message string for the exception.

status WebExceptionStatus

The network status of the exception.

Properties

Response

Gets the response that the remote host returned.

public WebResponse Response { get; }

Property Value

WebResponse

If a response is available from the Internet resource, a WebResponse instance that contains the error response from an Internet resource; otherwise, null.

Status

Gets the WebExceptionStatus code.

public WebExceptionStatus Status { get; }

Property Value

WebExceptionStatus

One of the WebExceptionStatus values.