System.Net.WebException Class

public class WebException : InvalidOperationException

Base Types

Object
  Exception
    SystemException
      InvalidOperationException
        WebException

Assembly

System

Library

Networking

Summary

Represents an error that occurs while accessing the Internet through a pluggable protocol.

Description

[Note: WebException is thrown by classes derived from WebRequest and WebResponse that implement pluggable protocols when an error occurs in while accessing the Internet.

When WebException is thrown by a method in a class derived from WebRequest , the System.Net.WebException.Response property provides the Internet response to the application.

]

See Also

System.Net Namespace

Members

WebException Constructors

WebException() Constructor
WebException(System.String) Constructor
WebException(System.String, System.Exception) Constructor
WebException(System.String, System.Net.WebExceptionStatus) Constructor
WebException(System.String, System.Exception, System.Net.WebExceptionStatus, System.Net.WebResponse) Constructor

WebException Properties

WebException.Response Property
WebException.Status Property


WebException() Constructor

public WebException();

Summary

Constructs and initializes a new instance of the WebException class.

Description

This constructor initializes the System.Net.WebException.Message property of the new instance to a system-supplied message that describes the error. This message takes into account the current system culture. The System.Net.WebException.InnerException and System.Net.WebException.Response properties of the new instance are initialized to null . The System.Net.WebException.Status property is initialized to System.Net.WebException.Status.UnknownError.

See Also

System.Net.WebException Class, System.Net Namespace

WebException(System.String) Constructor

public WebException(string message);

Summary

Constructs and initializes a new instance of the WebException class.

Parameters

message
A String that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.

Description

This constructor initializes the System.Net.WebException.Message property of the new instance using message. If message is null , the System.Net.WebException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.

The System.Net.WebException.InnerException and System.Net.WebException.Response properties of the new instance are initialized to null . The System.Net.WebException.Status property is initialized to System.Net.WebException.Status.UnknownError.

See Also

System.Net.WebException Class, System.Net Namespace

WebException(System.String, System.Exception) Constructor

public WebException(string message, Exception innerException);

Summary

Constructs and initializes a new instance of the WebException class.

Parameters

message
A String that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
innerException
An instance of Exception that is the cause of the current exception. If innerException is non-null, then the current Exception was raised in a catch block handling innerException .

Description

This constructor initializes the System.Net.WebException.Message property of the new instance using message and the System.Net.WebException.InnerException property using innerException. If message is null , the System.Net.WebException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.

The System.Net.WebException.Response property of the new instance are initialized to null . The System.Net.WebException.Status property is initialized to System.Net.WebException.Status.UnknownError.

[Note: For more information on inner exceptions, see System.Exception.InnerException.]

See Also

System.Net.WebException Class, System.Net Namespace

WebException(System.String, System.Net.WebExceptionStatus) Constructor

public WebException(string message, WebExceptionStatus status);

Summary

Constructs and initializes a new instance of the WebException class.

Parameters

message
A String that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
status
A WebExceptionStatus value that describes the status of the network connection after the exception is thrown.

Description

This constructor initializes the System.Net.WebException.Message property of the new instance using message and System.Net.WebException.Status using status. If message is null , the System.Net.WebException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.

The System.Net.WebException.InnerException and System.Net.WebException.Response properties of the new instance are initialized to null .

See Also

System.Net.WebException Class, System.Net Namespace

WebException(System.String, System.Exception, System.Net.WebExceptionStatus, System.Net.WebResponse) Constructor

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

Summary

Constructs and initializes a new instance of the WebException class with the specified error message, nested exception, status, and response.

Parameters

message
A String that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture.
innerException
An instance of Exception that is the cause of the current exception. If innerException is non-null, then the current Exception was raised in a catch block handling innerException .
status
A WebExceptionStatus value that describes the status of the network connection after the exception is thrown.
response
A WebResponse instance containing the response from the host.

Description

This constructor initializes the System.Net.WebException.Message property of the new instance using message, the System.Net.WebException.Status property using status, the System.Net.WebException.InnerException property using innerException, and the System.Net.WebException.Response property using response. If message is null , the System.Net.WebException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.

See Also

System.Net.WebException Class, System.Net Namespace

WebException.Response Property

public WebResponse Response { get; }

Summary

Gets the WebResponse that the host returned.

Property Value

A WebResponse instance containing the error response if one is available; otherwise, null .

Description

This property is read-only.

[Note: Some Internet protocols, such as HTTP, return otherwise valid responses indicating that an error has occurred at the protocol level. When the response to an Internet request indicates an error, System.Net.WebRequest.GetResponse sets the System.Net.WebException.Status property to System.Net.WebExceptionStatus.ProtocolError and provides the WebResponse containing the error message in the System.Net.WebException.Response property of the WebException that was thrown. The WebResponse can be examined to determine the actual error.]

See Also

System.Net.WebException Class, System.Net Namespace

WebException.Status Property

public WebExceptionStatus Status { get; }

Summary

Gets a value that indicates the status of the response.

Property Value

A WebExceptionStatus value that indicates the status of the response.

Description

This property is read-only.

The System.Net.WebException.Status property indicates the reason for the current exception.

The default value for this property is System.Net.WebExceptionStatus.UnknownError.

See Also

System.Net.WebException Class, System.Net Namespace