public class WebException : InvalidOperationException
Object
Exception
SystemException
InvalidOperationException
WebException
System
Networking
Represents an error that occurs while accessing the Internet through a pluggable protocol.
[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.
]
System.Net Namespace
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
public WebException();
Constructs and initializes a new instance of the WebException class.
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 tonull
. The System.Net.WebException.Status property is initialized to System.Net.WebException.Status.UnknownError.
System.Net.WebException Class, System.Net Namespace
public WebException(string message);
Constructs and initializes a new instance of the WebException class.
- 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.
This constructor initializes the System.Net.WebException.Message property of the new instance using message. If message isnull
, 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.
System.Net.WebException Class, System.Net Namespace
public WebException(string message, Exception innerException);
Constructs and initializes a new instance of the WebException class.
- 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 .
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 isnull
, 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.]
System.Net.WebException Class, System.Net Namespace
public WebException(string message, WebExceptionStatus status);
Constructs and initializes a new instance of the WebException class.
- 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.
This constructor initializes the System.Net.WebException.Message property of the new instance using message and System.Net.WebException.Status using status. If message isnull
, 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
.
System.Net.WebException Class, System.Net Namespace
public WebException(string message, Exception innerException, WebExceptionStatus status, WebResponse response);
Constructs and initializes a new instance of the WebException class with the specified error message, nested exception, status, and response.
- 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.
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 isnull
, the System.Net.WebException.Message property is initialized to the system-supplied message provided by the constructor that takes no arguments.
System.Net.WebException Class, System.Net Namespace
public WebResponse Response { get; }
Gets the WebResponse that the host returned.
A WebResponse instance containing the error response if one is available; otherwise,null
.
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.]
System.Net.WebException Class, System.Net Namespace
public WebExceptionStatus Status { get; }
Gets a value that indicates the status of the response.
A WebExceptionStatus value that indicates the status of the response.
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.
System.Net.WebException Class, System.Net Namespace